diff --git a/.editorconfig b/.editorconfig index c3fb970c3..fa43757a9 100644 --- a/.editorconfig +++ b/.editorconfig @@ -6,7 +6,7 @@ indent_style = space indent_size = 4 csharp_style_var_for_built_in_types = false:warning csharp_style_var_elsewhere = false:warning -csharp_style_var_when_type_is_apparent = false:warning +csharp_style_var_when_type_is_apparent = true:warning end_of_line = crlf dotnet_sort_system_directives_first = true dotnet_style_predefined_type_for_locals_parameters_members = true:warning diff --git a/ImageSharp.ruleset b/ImageSharp.ruleset index 3f10206fc..0bd9cd11a 100644 --- a/ImageSharp.ruleset +++ b/ImageSharp.ruleset @@ -4,7 +4,7 @@ - + diff --git a/ImageSharp.sln b/ImageSharp.sln index 8ec2cf53b..2e0cbd52e 100644 --- a/ImageSharp.sln +++ b/ImageSharp.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26403.3 +VisualStudioVersion = 15.0.26403.7 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionItems", "{C317F1B1-D75E-4C6D-83EB-80367343E0D7}" ProjectSection(SolutionItems) = preProject @@ -16,8 +16,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionIt ImageSharp.sln.DotSettings = ImageSharp.sln.DotSettings NuGet.config = NuGet.config README.md = README.md - Rebracer.xml = Rebracer.xml - Settings.StyleCop = Settings.StyleCop EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Source", "Source", "{815C0625-CD3D-440F-9F80-2D83856AB7AE}" diff --git a/README.md b/README.md index 4d079de39..ca2427546 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -# ImageSharp ImageSharp +# ImageSharp ImageSharp **ImageSharp** is a new, fully featured, fully managed, cross-platform, 2D graphics API designed to allow the processing of images without the use of `System.Drawing`. @@ -39,8 +39,8 @@ The **ImageSharp** library is made up of multiple packages. Packages include: - **ImageSharp** - - Contains the Image classes, PixelFormats, Primitives, Configuration, and other core functionality. - - The IImageFormat interface, Jpeg, Png, Bmp, and Gif formats. + - Contains the generic `Image` class, 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. @@ -77,13 +77,16 @@ Without the constraints of `System.Drawing` We have been able to develop somethi Gone are system-wide process-locks; ImageSharp images are thread-safe and fully supported in web environments. -Many `Image` methods are also fluent. +Many `Image` methods are also fluent. Here's an example of the code required to resize an image using the default Bicubic resampler then turn the colors into their grayscale equivalent using the BT709 standard matrix. +`Rgba32` is our default PixelFormat, equivalent to `System.Drawing Color`. + On platforms supporting netstandard 1.3+ ```csharp -using (Image image = Image.Load("foo.jpg")) +// Image.Load(string path) is a shortcut for our default type. Other pixel formats use Image.Load(string path)) +using (Image image = Image.Load("foo.jpg")) { image.Resize(image.Width / 2, image.Height / 2) .Grayscale() @@ -92,9 +95,10 @@ using (Image image = Image.Load("foo.jpg")) ``` on netstandard 1.1 - 1.2 ```csharp +// Image.Load(Stream stream) is a shortcut for our default type. Other pixel formats use Image.Load(Stream stream)) using (FileStream stream = File.OpenRead("foo.jpg")) using (FileStream output = File.OpenWrite("bar.jpg")) -using (Image image = Image.Load(stream)) +using (Image image = Image.Load(stream)) { image.Resize(image.Width / 2, image.Height / 2) .Grayscale() @@ -105,15 +109,14 @@ using (Image image = Image.Load(stream)) Setting individual pixel values is perfomed as follows: ```csharp -using (image = new Image(400, 400) -using (var pixels = image.Lock()) +using (Image image = new Image(400, 400) +using (PixelAccessor pixels = image.Lock()) { - // 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 there are multiple [PixelFormat implementations](https://github.com/JimBobSquarePants/ImageSharp/tree/master/src/ImageSharp/PixelFormats) 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. @@ -121,7 +124,7 @@ All in all this should allow image processing to be much more accessible to deve Please... Spread the word, contribute algorithms, submit performance improvements, unit tests. -Performance is a biggie, if you know anything about the new vector types and can apply some fancy new stuff with that it would be awesome. +Performance is a biggie, if you know anything about the `System.Numerics.Vectors` types and can apply some fancy new stuff with that it would be awesome. There's a lot of developers out there who could write this stuff a lot better and faster than I and I would love to see what we collectively can come up with so please, if you can help in any way it would be most welcome and benificial for all. diff --git a/Rebracer.xml b/Rebracer.xml deleted file mode 100644 index 9b0a654d2..000000000 --- a/Rebracer.xml +++ /dev/null @@ -1,249 +0,0 @@ - - - - - - - - - - - - - HACK:2 - TODO:2 - UNDONE:2 - UnresolvedMergeConflict:3 - - false - false - false - - - - - 0 - 0 - 1 - 1 - -1 - -1 - 0 - 1 - 0 - 1 - 1 - 1 - 1 - 1 - 0 - 1 - 1 - 0 - 2 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 0 - 1 - 0 - 1 - 0 - 0 - 0 - 1 - 1 - 1 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 1 - 0 - 0 - 0 - 0 - 0 - 0 - 1 - 1 - 0 - 1 - 0 - 0 - 0 - 1 - 1 - - - false - true - true - true - true - Implicit (Windows)|$(VSInstallDir)\JavaScript\References\libhelp.js|$(VSInstallDir)\JavaScript\References\domWindows.js|$(VSInstallDir)\JavaScript\References\underscorefilter.js|$(VSInstallDir)\JavaScript\References\showPlainComments.js;Implicit (Windows 8.1)|$(VSInstallDir)\JavaScript\References\libhelp.js|$(VSInstallDir)\JavaScript\References\sitetypesWindows.js|$(VSInstallDir)\JavaScript\References\domWindows_8.1.js|$(VSInstallDir)\JavaScript\References\underscorefilter.js|$(VSInstallDir)\JavaScript\References\showPlainComments.js;Implicit (Windows Phone 8.1)|$(VSInstallDir)\JavaScript\References\libhelp.js|$(VSInstallDir)\JavaScript\References\sitetypesWindows.js|$(VSInstallDir)\JavaScript\References\domWindowsPhone_8.1.js|$(VSInstallDir)\JavaScript\References\underscorefilter.js|$(VSInstallDir)\JavaScript\References\showPlainComments.js;Implicit (Web)|$(VSInstallDir)\JavaScript\References\libhelp.js|$(VSInstallDir)\JavaScript\References\sitetypesWeb.js|$(VSInstallDir)\JavaScript\References\domWeb.js|$(VSInstallDir)\JavaScript\References\underscorefilter.js|$(VSInstallDir)\JavaScript\References\showPlainComments.js|C:\Users\james.south\AppData\Local\Web Essentials 2015\Modern.Intellisense.js;Dedicated Worker|$(VSInstallDir)\JavaScript\References\libhelp.js|$(VSInstallDir)\JavaScript\References\dedicatedworker.js|$(VSInstallDir)\JavaScript\References\underscorefilter.js|$(VSInstallDir)\JavaScript\References\showPlainComments.js;Generic|$(VSInstallDir)\JavaScript\References\libhelp.js|$(VSInstallDir)\JavaScript\References\underscorefilter.js|$(VSInstallDir)\JavaScript\References\showPlainComments.js; - true - true - true - false - true - true - false - false - true - true - - - true - false - false - true - true - true - 1 - true - false - true - true - false - false - false - false - false - false - false - true - true - false - true - true - true - true - false - true - false - false - true - false - 1 - true - 2 - 2 - false - false - 0 - true - true - 0 - 0 - true - true - false - 0 - 0 - false - 0 - 1 - false - true - false - 2 - true - false - false - false - false - true - true - false - false - false - false - true - true - 2 - 2 - 2 - true - false - false - true - true - false - false - 1 - true - false - false - false - false - false - false - false - false - false - false - false - true - false - false - true - true - - - false - false - true - false - true - true - true - true - true - true - true - false - true - true - false - false - true - true - false - false - false - false - false - false - false - false - - - false - true - true - true - false - true - true - true - - - - \ No newline at end of file diff --git a/Settings.StyleCop b/Settings.StyleCop deleted file mode 100644 index 2716e8d0a..000000000 --- a/Settings.StyleCop +++ /dev/null @@ -1,56 +0,0 @@ - - - - enum - exif - uint - lossy - octree - png - quantizer - unzig - cb - cr - Laplacian - Sobel - Scharr - rgb - rgba - rrggbb - rrggbbaa - scanline - scanlines - png's - codeword - unscaled - zig-zag - crc - zlib - xff - xda - ss - Vol - pp - cmyk - Paeth - th - bool - bools - desensitivity - premultiplied - endianness - thresholding - - - - - - James Jackson-South - - Copyright © James Jackson-South and contributors. - Licensed under the Apache License, Version 2.0. - - - - - \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Brushes/Brushes.cs b/src/ImageSharp.Drawing/Brushes/Brushes.cs index 8998c60f6..e39f3dd49 100644 --- a/src/ImageSharp.Drawing/Brushes/Brushes.cs +++ b/src/ImageSharp.Drawing/Brushes/Brushes.cs @@ -8,149 +8,251 @@ namespace ImageSharp.Drawing.Brushes using ImageSharp.PixelFormats; /// - /// A collection of methods for creating brushes. Brushes use for painting. + /// A collection of methods for creating generic brushes. /// - public class Brushes + /// A New + public static class Brushes { + /// + /// Percent10 Hatch Pattern + /// + /// ---> x axis + /// ^ + /// | y - axis + /// | + /// see PatternBrush for details about how to make new patterns work + private static readonly bool[,] Percent10Pattern = + { + { true, false, false, false }, + { false, false, false, false }, + { false, false, true, false }, + { false, false, false, false } + }; + + /// + /// Percent20 pattern. + /// + private static readonly bool[,] Percent20Pattern = + { + { true, false, false, false }, + { false, false, true, false }, + { true, false, false, false }, + { false, false, true, false } + }; + + /// + /// Horizontal Hatch Pattern + /// + private static readonly bool[,] HorizontalPattern = + { + { false }, + { true }, + { false }, + { false } + }; + + /// + /// Min Pattern + /// + private static readonly bool[,] MinPattern = + { + { false }, + { false }, + { false }, + { true } + }; + + /// + /// Vertical Pattern + /// + private static readonly bool[,] VerticalPattern = + { + { false, true, false, false }, + }; + + /// + /// Forward Diagonal Pattern + /// + private static readonly bool[,] ForwardDiagonalPattern = + { + { false, false, false, true }, + { false, false, true, false }, + { false, true, false, false }, + { true, false, false, false } + }; + + /// + /// Backward Diagonal Pattern + /// + private static readonly bool[,] BackwardDiagonalPattern = + { + { true, false, false, false }, + { false, true, false, false }, + { false, false, true, false }, + { false, false, false, true } + }; + /// /// Create as brush that will paint a solid color /// /// The color. - /// A Brush - public static SolidBrush Solid(Rgba32 color) - => new SolidBrush(color); + /// The pixel format. + /// A New + public static SolidBrush Solid(TPixel color) + where TPixel : struct, IPixel + => new SolidBrush(color); /// - /// Create as brush that will paint a Percent10 Hatch Pattern with - /// in the specified foreground color and a transparent background + /// Create as brush that will paint a Percent10 Hatch Pattern with the specified colors /// /// Color of the foreground. - /// A Brush - public static PatternBrush Percent10(Rgba32 foreColor) - => new PatternBrush(Brushes.Percent10(foreColor, Rgba32.Transparent)); + /// The pixel format. + /// A New + public static PatternBrush Percent10(TPixel foreColor) + where TPixel : struct, IPixel + => new PatternBrush(foreColor, NamedColors.Transparent, Percent10Pattern); /// - /// Create as brush that will paint a Percent10 Hatch Pattern with - /// in the specified foreground and background colors + /// Create as brush that will paint a Percent10 Hatch Pattern with the specified colors /// /// Color of the foreground. /// Color of the background. - /// A Brush - public static PatternBrush Percent10(Rgba32 foreColor, Rgba32 backColor) - => new PatternBrush(Brushes.Percent10(foreColor, backColor)); + /// The pixel format. + /// A New + public static PatternBrush Percent10(TPixel foreColor, TPixel backColor) + where TPixel : struct, IPixel + => new PatternBrush(foreColor, backColor, Percent10Pattern); /// - /// Create as brush that will paint a Percent20 Hatch Pattern with - /// in the specified foreground color and a transparent background + /// Create as brush that will paint a Percent20 Hatch Pattern with the specified foreground color and a + /// transparent background. /// /// Color of the foreground. - /// A Brush - public static PatternBrush Percent20(Rgba32 foreColor) - => new PatternBrush(Brushes.Percent20(foreColor, Rgba32.Transparent)); + /// The pixel format. + /// A New + public static PatternBrush Percent20(TPixel foreColor) + where TPixel : struct, IPixel + => new PatternBrush(foreColor, NamedColors.Transparent, Percent20Pattern); /// - /// Create as brush that will paint a Percent20 Hatch Pattern with - /// in the specified foreground and background colors + /// Create as brush that will paint a Percent20 Hatch Pattern with the specified colors /// /// Color of the foreground. /// Color of the background. - /// A Brush - public static PatternBrush Percent20(Rgba32 foreColor, Rgba32 backColor) - => new PatternBrush(Brushes.Percent20(foreColor, backColor)); + /// The pixel format. + /// A New + public static PatternBrush Percent20(TPixel foreColor, TPixel backColor) + where TPixel : struct, IPixel + => new PatternBrush(foreColor, backColor, Percent20Pattern); /// - /// Create as brush that will paint a Horizontal Hatch Pattern with - /// in the specified foreground color and a transparent background + /// Create as brush that will paint a Horizontal Hatch Pattern with the specified foreground color and a + /// transparent background. /// /// Color of the foreground. - /// A Brush - public static PatternBrush Horizontal(Rgba32 foreColor) - => new PatternBrush(Brushes.Horizontal(foreColor, Rgba32.Transparent)); + /// The pixel format. + /// A New + public static PatternBrush Horizontal(TPixel foreColor) + where TPixel : struct, IPixel + => new PatternBrush(foreColor, NamedColors.Transparent, HorizontalPattern); /// - /// Create as brush that will paint a Horizontal Hatch Pattern with - /// in the specified foreground and background colors + /// Create as brush that will paint a Horizontal Hatch Pattern with the specified colors /// /// Color of the foreground. /// Color of the background. - /// A Brush - public static PatternBrush Horizontal(Rgba32 foreColor, Rgba32 backColor) - => new PatternBrush(Brushes.Horizontal(foreColor, backColor)); + /// The pixel format. + /// A New + public static PatternBrush Horizontal(TPixel foreColor, TPixel backColor) + where TPixel : struct, IPixel + => new PatternBrush(foreColor, backColor, HorizontalPattern); /// - /// Create as brush that will paint a Min Hatch Pattern with - /// in the specified foreground color and a transparent background + /// Create as brush that will paint a Min Hatch Pattern with the specified foreground color and a + /// transparent background. /// /// Color of the foreground. - /// A Brush - public static PatternBrush Min(Rgba32 foreColor) - => new PatternBrush(Brushes.Min(foreColor, Rgba32.Transparent)); + /// The pixel format. + /// A New + public static PatternBrush Min(TPixel foreColor) + where TPixel : struct, IPixel + => new PatternBrush(foreColor, NamedColors.Transparent, MinPattern); /// - /// Create as brush that will paint a Min Hatch Pattern with - /// in the specified foreground and background colors + /// Create as brush that will paint a Min Hatch Pattern with the specified colors /// /// Color of the foreground. /// Color of the background. - /// A Brush - public static PatternBrush Min(Rgba32 foreColor, Rgba32 backColor) - => new PatternBrush(Brushes.Min(foreColor, backColor)); + /// The pixel format. + /// A New + public static PatternBrush Min(TPixel foreColor, TPixel backColor) + where TPixel : struct, IPixel + => new PatternBrush(foreColor, backColor, MinPattern); /// - /// Create as brush that will paint a Vertical Hatch Pattern with - /// in the specified foreground color and a transparent background + /// Create as brush that will paint a Vertical Hatch Pattern with the specified foreground color and a + /// transparent background. /// /// Color of the foreground. - /// A Brush - public static PatternBrush Vertical(Rgba32 foreColor) - => new PatternBrush(Brushes.Vertical(foreColor, Rgba32.Transparent)); + /// The pixel format. + /// A New + public static PatternBrush Vertical(TPixel foreColor) + where TPixel : struct, IPixel + => new PatternBrush(foreColor, NamedColors.Transparent, VerticalPattern); /// - /// Create as brush that will paint a Vertical Hatch Pattern with - /// in the specified foreground and background colors + /// Create as brush that will paint a Vertical Hatch Pattern with the specified colors /// /// Color of the foreground. /// Color of the background. - /// A Brush - public static PatternBrush Vertical(Rgba32 foreColor, Rgba32 backColor) - => new PatternBrush(Brushes.Vertical(foreColor, backColor)); + /// The pixel format. + /// A New + public static PatternBrush Vertical(TPixel foreColor, TPixel backColor) + where TPixel : struct, IPixel + => new PatternBrush(foreColor, backColor, VerticalPattern); /// - /// Create as brush that will paint a Forward Diagonal Hatch Pattern with - /// in the specified foreground color and a transparent background + /// Create as brush that will paint a Forward Diagonal Hatch Pattern with the specified foreground color and a + /// transparent background. /// /// Color of the foreground. - /// A Brush - public static PatternBrush ForwardDiagonal(Rgba32 foreColor) - => new PatternBrush(Brushes.ForwardDiagonal(foreColor, Rgba32.Transparent)); + /// The pixel format. + /// A New + public static PatternBrush ForwardDiagonal(TPixel foreColor) + where TPixel : struct, IPixel + => new PatternBrush(foreColor, NamedColors.Transparent, ForwardDiagonalPattern); /// - /// Create as brush that will paint a Forward Diagonal Hatch Pattern with - /// in the specified foreground and background colors + /// Create as brush that will paint a Forward Diagonal Hatch Pattern with the specified colors /// /// Color of the foreground. /// Color of the background. - /// A Brush - public static PatternBrush ForwardDiagonal(Rgba32 foreColor, Rgba32 backColor) - => new PatternBrush(Brushes.ForwardDiagonal(foreColor, backColor)); + /// The pixel format. + /// A New + public static PatternBrush ForwardDiagonal(TPixel foreColor, TPixel backColor) + where TPixel : struct, IPixel + => new PatternBrush(foreColor, backColor, ForwardDiagonalPattern); /// - /// Create as brush that will paint a Backward Diagonal Hatch Pattern with - /// in the specified foreground color and a transparent background + /// Create as brush that will paint a Backward Diagonal Hatch Pattern with the specified foreground color and a + /// transparent background. /// /// Color of the foreground. - /// A Brush - public static PatternBrush BackwardDiagonal(Rgba32 foreColor) - => new PatternBrush(Brushes.BackwardDiagonal(foreColor, Rgba32.Transparent)); + /// The pixel format. + /// A New + public static PatternBrush BackwardDiagonal(TPixel foreColor) + where TPixel : struct, IPixel + => new PatternBrush(foreColor, NamedColors.Transparent, BackwardDiagonalPattern); /// - /// Create as brush that will paint a Backward Diagonal Hatch Pattern with - /// in the specified foreground and background colors + /// Create as brush that will paint a Backward Diagonal Hatch Pattern with the specified colors /// /// Color of the foreground. /// Color of the background. - /// A Brush - public static PatternBrush BackwardDiagonal(Rgba32 foreColor, Rgba32 backColor) - => new PatternBrush(Brushes.BackwardDiagonal(foreColor, backColor)); + /// The pixel format. + /// A New + public static PatternBrush BackwardDiagonal(TPixel foreColor, TPixel backColor) + where TPixel : struct, IPixel + => new PatternBrush(foreColor, backColor, BackwardDiagonalPattern); } } \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Brushes/Brushes{TPixel}.cs b/src/ImageSharp.Drawing/Brushes/Brushes{TPixel}.cs deleted file mode 100644 index 4b2f6c026..000000000 --- a/src/ImageSharp.Drawing/Brushes/Brushes{TPixel}.cs +++ /dev/null @@ -1,168 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp.Drawing.Brushes -{ - using ImageSharp.PixelFormats; - - /// - /// A collection of methods for creating generic brushes. - /// - /// The pixel format. - /// A Brush - public class Brushes - where TPixel : struct, IPixel - { - /// - /// Percent10 Hatch Pattern - /// - /// ---> x axis - /// ^ - /// | y - axis - /// | - /// see PatternBrush for details about how to make new patterns work - private static readonly bool[,] Percent10Pattern = - { - { true, false, false, false }, - { false, false, false, false }, - { false, false, true, false }, - { false, false, false, false } - }; - - /// - /// Percent20 pattern. - /// - private static readonly bool[,] Percent20Pattern = - { - { true, false, false, false }, - { false, false, true, false }, - { true, false, false, false }, - { false, false, true, false } - }; - - /// - /// Horizontal Hatch Pattern - /// - private static readonly bool[,] HorizontalPattern = - { - { false }, - { true }, - { false }, - { false } - }; - - /// - /// Min Pattern - /// - private static readonly bool[,] MinPattern = - { - { false }, - { false }, - { false }, - { true } - }; - - /// - /// Vertical Pattern - /// - private static readonly bool[,] VerticalPattern = - { - { false, true, false, false }, - }; - - /// - /// Forward Diagonal Pattern - /// - private static readonly bool[,] ForwardDiagonalPattern = - { - { false, false, false, true }, - { false, false, true, false }, - { false, true, false, false }, - { true, false, false, false } - }; - - /// - /// Backward Diagonal Pattern - /// - private static readonly bool[,] BackwardDiagonalPattern = - { - { true, false, false, false }, - { false, true, false, false }, - { false, false, true, false }, - { false, false, false, true } - }; - - /// - /// Create as brush that will paint a solid color - /// - /// The color. - /// A Brush - public static SolidBrush Solid(TPixel color) - => new SolidBrush(color); - - /// - /// Create as brush that will paint a Percent10 Hatch Pattern within the specified colors - /// - /// Color of the foreground. - /// Color of the background. - /// A Brush - 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 - /// - /// Color of the foreground. - /// Color of the background. - /// A Brush - 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 - /// - /// Color of the foreground. - /// Color of the background. - /// A Brush - 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 - /// - /// Color of the foreground. - /// Color of the background. - /// A Brush - 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 - /// - /// Color of the foreground. - /// Color of the background. - /// A Brush - 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 - /// - /// Color of the foreground. - /// Color of the background. - /// A Brush - 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 - /// - /// Color of the foreground. - /// Color of the background. - /// A Brush - public static PatternBrush BackwardDiagonal(TPixel foreColor, TPixel backColor) - => new PatternBrush(foreColor, backColor, BackwardDiagonalPattern); - } -} diff --git a/src/ImageSharp.Drawing/Brushes/ImageBrush.cs b/src/ImageSharp.Drawing/Brushes/ImageBrush.cs deleted file mode 100644 index 6a3ff1d9d..000000000 --- a/src/ImageSharp.Drawing/Brushes/ImageBrush.cs +++ /dev/null @@ -1,24 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp.Drawing.Brushes -{ - using ImageSharp.PixelFormats; - - /// - /// Provides an implementation of a solid brush for painting with repeating images. The brush uses for painting. - /// - public class ImageBrush : ImageBrush - { - /// - /// Initializes a new instance of the class. - /// - /// The image to paint. - public ImageBrush(IImageBase image) - : base(image) - { - } - } -} diff --git a/src/ImageSharp.Drawing/Brushes/ImageBrush{TPixel}.cs b/src/ImageSharp.Drawing/Brushes/ImageBrush{TPixel}.cs index 5038ea01b..6f851e5c3 100644 --- a/src/ImageSharp.Drawing/Brushes/ImageBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Brushes/ImageBrush{TPixel}.cs @@ -5,7 +5,10 @@ namespace ImageSharp.Drawing.Brushes { + using System; using System.Numerics; + + using ImageSharp.Memory; using ImageSharp.PixelFormats; using Processors; @@ -114,7 +117,7 @@ namespace ImageSharp.Drawing.Brushes } /// - internal override void Apply(BufferSpan scanline, int x, int y) + internal override void Apply(Span scanline, int x, int y) { // create a span for colors using (Buffer amountBuffer = new Buffer(scanline.Length)) @@ -122,7 +125,7 @@ namespace ImageSharp.Drawing.Brushes { int sourceY = (y - this.offsetY) % this.yLength; int offsetX = x - this.offsetX; - BufferSpan sourceRow = this.source.GetRowSpan(sourceY); + Span sourceRow = this.source.GetRowSpan(sourceY); for (int i = 0; i < scanline.Length; i++) { @@ -133,7 +136,7 @@ namespace ImageSharp.Drawing.Brushes overlay[i] = pixel; } - BufferSpan destinationRow = this.Target.GetRowSpan(x, y).Slice(0, scanline.Length); + Span destinationRow = this.Target.GetRowSpan(x, y).Slice(0, scanline.Length); this.Blender.Blend(destinationRow, destinationRow, overlay, amountBuffer); } } diff --git a/src/ImageSharp.Drawing/Brushes/PatternBrush.cs b/src/ImageSharp.Drawing/Brushes/PatternBrush.cs deleted file mode 100644 index f00862fe7..000000000 --- a/src/ImageSharp.Drawing/Brushes/PatternBrush.cs +++ /dev/null @@ -1,35 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp.Drawing.Brushes -{ - using ImageSharp.PixelFormats; - - /// - /// Provides an implementation of a pattern brush for painting patterns. The brush use for painting. - /// - public class PatternBrush : PatternBrush - { - /// - /// Initializes a new instance of the class. - /// - /// Color of the fore. - /// Color of the back. - /// The pattern. - public PatternBrush(Rgba32 foreColor, Rgba32 backColor, bool[,] pattern) - : base(foreColor, backColor, pattern) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The brush. - internal PatternBrush(PatternBrush brush) - : base(brush) - { - } - } -} \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Brushes/PatternBrush{TPixel}.cs b/src/ImageSharp.Drawing/Brushes/PatternBrush{TPixel}.cs index dc8a4bc90..90990e54a 100644 --- a/src/ImageSharp.Drawing/Brushes/PatternBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Brushes/PatternBrush{TPixel}.cs @@ -7,6 +7,8 @@ namespace ImageSharp.Drawing.Brushes { using System; using System.Numerics; + + using ImageSharp.Memory; using ImageSharp.PixelFormats; using Processors; @@ -147,7 +149,7 @@ namespace ImageSharp.Drawing.Brushes } /// - internal override void Apply(BufferSpan scanline, int x, int y) + internal override void Apply(Span scanline, int x, int y) { int patternY = y % this.pattern.Height; using (Buffer amountBuffer = new Buffer(scanline.Length)) @@ -161,7 +163,7 @@ namespace ImageSharp.Drawing.Brushes overlay[i] = this.pattern[patternY, patternX]; } - BufferSpan destinationRow = this.Target.GetRowSpan(x, y).Slice(0, scanline.Length); + Span destinationRow = this.Target.GetRowSpan(x, y).Slice(0, scanline.Length); this.Blender.Blend(destinationRow, destinationRow, overlay, amountBuffer); } } diff --git a/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs b/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs index d7c70220c..29629324a 100644 --- a/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs +++ b/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs @@ -7,6 +7,8 @@ namespace ImageSharp.Drawing.Processors { using System; using System.Numerics; + + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// @@ -64,7 +66,7 @@ namespace ImageSharp.Drawing.Processors /// The x position in the target pixel space that the start of the scanline data corresponds to. /// The y position in the target pixel space that whole scanline corresponds to. /// scanlineBuffer will be > scanlineWidth but provide and offset in case we want to share a larger buffer across runs. - internal virtual void Apply(BufferSpan scanline, int x, int y) + internal virtual void Apply(Span scanline, int x, int y) { using (Buffer amountBuffer = new Buffer(scanline.Length)) using (Buffer overlay = new Buffer(scanline.Length)) @@ -79,7 +81,7 @@ namespace ImageSharp.Drawing.Processors overlay[i] = this[x + i, y]; } - BufferSpan destinationRow = this.Target.GetRowSpan(x, y).Slice(0, scanline.Length); + Span destinationRow = this.Target.GetRowSpan(x, y).Slice(0, scanline.Length); this.Blender.Blend(destinationRow, destinationRow, overlay, amountBuffer); } } diff --git a/src/ImageSharp.Drawing/Brushes/RecolorBrush.cs b/src/ImageSharp.Drawing/Brushes/RecolorBrush.cs deleted file mode 100644 index bfe5c01e6..000000000 --- a/src/ImageSharp.Drawing/Brushes/RecolorBrush.cs +++ /dev/null @@ -1,26 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp.Drawing.Brushes -{ - using ImageSharp.PixelFormats; - - /// - /// Provides an implementation of a recolor brush for painting color changes. - /// - public class RecolorBrush : RecolorBrush - { - /// - /// Initializes a new instance of the class. - /// - /// Color of the source. - /// Color of the target. - /// The threshold. - public RecolorBrush(Rgba32 sourceColor, Rgba32 targeTPixel, float threshold) - : base(sourceColor, targeTPixel, threshold) - { - } - } -} diff --git a/src/ImageSharp.Drawing/Brushes/RecolorBrush{TPixel}.cs b/src/ImageSharp.Drawing/Brushes/RecolorBrush{TPixel}.cs index a96202b7b..64b91e384 100644 --- a/src/ImageSharp.Drawing/Brushes/RecolorBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Brushes/RecolorBrush{TPixel}.cs @@ -5,7 +5,10 @@ namespace ImageSharp.Drawing.Brushes { + using System; using System.Numerics; + + using ImageSharp.Memory; using ImageSharp.PixelFormats; using Processors; @@ -139,7 +142,7 @@ namespace ImageSharp.Drawing.Brushes } /// - internal override void Apply(BufferSpan scanline, int x, int y) + internal override void Apply(Span scanline, int x, int y) { using (Buffer amountBuffer = new Buffer(scanline.Length)) using (Buffer overlay = new Buffer(scanline.Length)) @@ -155,7 +158,7 @@ namespace ImageSharp.Drawing.Brushes overlay[i] = this[offsetX, y]; } - BufferSpan destinationRow = this.Target.GetRowSpan(x, y).Slice(0, scanline.Length); + Span destinationRow = this.Target.GetRowSpan(x, y).Slice(0, scanline.Length); this.Blender.Blend(destinationRow, destinationRow, overlay, amountBuffer); } } diff --git a/src/ImageSharp.Drawing/Brushes/SolidBrush.cs b/src/ImageSharp.Drawing/Brushes/SolidBrush.cs deleted file mode 100644 index 8a3ad50e7..000000000 --- a/src/ImageSharp.Drawing/Brushes/SolidBrush.cs +++ /dev/null @@ -1,24 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp.Drawing.Brushes -{ - using ImageSharp.PixelFormats; - - /// - /// Provides an implementation of a solid brush for painting solid color areas. The brush uses for painting. - /// - public class SolidBrush : SolidBrush - { - /// - /// Initializes a new instance of the class. - /// - /// The color. - public SolidBrush(Rgba32 color) - : base(color) - { - } - } -} diff --git a/src/ImageSharp.Drawing/Brushes/SolidBrush{TPixel}.cs b/src/ImageSharp.Drawing/Brushes/SolidBrush{TPixel}.cs index 71b802136..28f7b0e45 100644 --- a/src/ImageSharp.Drawing/Brushes/SolidBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Brushes/SolidBrush{TPixel}.cs @@ -5,7 +5,10 @@ namespace ImageSharp.Drawing.Brushes { + using System; using System.Numerics; + + using ImageSharp.Memory; using ImageSharp.PixelFormats; using Processors; @@ -87,9 +90,9 @@ namespace ImageSharp.Drawing.Brushes } /// - internal override void Apply(BufferSpan scanline, int x, int y) + internal override void Apply(Span scanline, int x, int y) { - BufferSpan destinationRow = this.Target.GetRowSpan(x, y).Slice(0, scanline.Length); + Span destinationRow = this.Target.GetRowSpan(x, y).Slice(0, scanline.Length); using (Buffer amountBuffer = new Buffer(scanline.Length)) { diff --git a/src/ImageSharp.Drawing/DrawImage.cs b/src/ImageSharp.Drawing/DrawImage.cs index 920ad31cc..db40132c8 100644 --- a/src/ImageSharp.Drawing/DrawImage.cs +++ b/src/ImageSharp.Drawing/DrawImage.cs @@ -1,17 +1,15 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // namespace ImageSharp { - using System; using Drawing.Processors; - using ImageSharp.Drawing; using ImageSharp.PixelFormats; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { diff --git a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj b/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj index 15b7df2a2..a3552a09c 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-alpha8 + 1.0.0-alpha9 James Jackson-South and contributors netstandard1.1 true diff --git a/src/ImageSharp.Drawing/Pens/Pen.cs b/src/ImageSharp.Drawing/Pens/Pen.cs deleted file mode 100644 index a3cc3cbdf..000000000 --- a/src/ImageSharp.Drawing/Pens/Pen.cs +++ /dev/null @@ -1,55 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp.Drawing.Pens -{ - using ImageSharp.PixelFormats; - - /// - /// Represents a in the color space. - /// - public class Pen : Pen - { - /// - /// Initializes a new instance of the class. - /// - /// The color. - /// The width. - public Pen(Rgba32 color, float width) - : base(color, width) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The brush. - /// The width. - public Pen(IBrush brush, float width) - : base(brush, width) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The brush. - /// The width. - /// The pattern. - public Pen(IBrush brush, float width, float[] pattern) - : base(brush, width, pattern) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The pen. - internal Pen(Pen pen) - : base(pen) - { - } - } -} \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Pens/Pens.cs b/src/ImageSharp.Drawing/Pens/Pens.cs index 5c91df226..364115cb7 100644 --- a/src/ImageSharp.Drawing/Pens/Pens.cs +++ b/src/ImageSharp.Drawing/Pens/Pens.cs @@ -10,86 +10,121 @@ namespace ImageSharp.Drawing.Pens /// /// Common Pen styles /// - public class Pens + public static class Pens { + private static readonly float[] DashDotPattern = new[] { 3f, 1f, 1f, 1f }; + private static readonly float[] DashDotDotPattern = new[] { 3f, 1f, 1f, 1f, 1f, 1f }; + private static readonly float[] DottedPattern = new[] { 1f, 1f }; + private static readonly float[] DashedPattern = new[] { 3f, 1f }; + /// /// Create a solid pen with out any drawing patterns /// /// The color. /// The width. + /// The type of the color. /// The Pen - public static Pen Solid(Rgba32 color, float width) => new Pen(color, width); + public static Pen Solid(TPixel color, float width) + where TPixel : struct, IPixel + => new Pen(color, width); /// /// Create a solid pen with out any drawing patterns /// /// The brush. /// The width. + /// The type of the color. /// The Pen - public static Pen Solid(IBrush brush, float width) => new Pen(brush, width); + public static Pen Solid(IBrush brush, float width) + where TPixel : struct, IPixel + => new Pen(brush, width); /// /// Create a pen with a 'Dash' drawing patterns /// /// The color. /// The width. + /// The type of the color. /// The Pen - public static Pen Dash(Rgba32 color, float width) => new Pen(Pens.Dash(color, width)); + public static Pen Dash(TPixel color, float width) + where TPixel : struct, IPixel + => new Pen(color, width, DashedPattern); /// /// Create a pen with a 'Dash' drawing patterns /// /// The brush. /// The width. + /// The type of the color. /// The Pen - public static Pen Dash(IBrush brush, float width) => new Pen(Pens.Dash(brush, width)); + public static Pen Dash(IBrush brush, float width) + where TPixel : struct, IPixel + => new Pen(brush, width, DashedPattern); /// /// Create a pen with a 'Dot' drawing patterns /// /// The color. /// The width. + /// The type of the color. /// The Pen - public static Pen Dot(Rgba32 color, float width) => new Pen(Pens.Dot(color, width)); + public static Pen Dot(TPixel color, float width) + where TPixel : struct, IPixel + => new Pen(color, width, DottedPattern); /// /// Create a pen with a 'Dot' drawing patterns /// /// The brush. /// The width. + /// The type of the color. /// The Pen - public static Pen Dot(IBrush brush, float width) => new Pen(Pens.Dot(brush, width)); + public static Pen Dot(IBrush brush, float width) + where TPixel : struct, IPixel + => new Pen(brush, width, DottedPattern); /// /// Create a pen with a 'Dash Dot' drawing patterns /// /// The color. /// The width. + /// The type of the color. /// The Pen - public static Pen DashDot(Rgba32 color, float width) => new Pen(Pens.DashDot(color, width)); + public static Pen DashDot(TPixel color, float width) + where TPixel : struct, IPixel + => new Pen(color, width, DashDotPattern); /// /// Create a pen with a 'Dash Dot' drawing patterns /// /// The brush. /// The width. + /// The type of the color. /// The Pen - public static Pen DashDot(IBrush brush, float width) => new Pen(Pens.DashDot(brush, width)); + public static Pen DashDot(IBrush brush, float width) + where TPixel : struct, IPixel + => new Pen(brush, width, DashDotPattern); /// /// Create a pen with a 'Dash Dot Dot' drawing patterns /// /// The color. /// The width. + /// The type of the color. /// The Pen - public static Pen DashDotDot(Rgba32 color, float width) => new Pen(Pens.DashDotDot(color, width)); + public static Pen DashDotDot(TPixel color, float width) + where TPixel : struct, IPixel + => new Pen(color, width, DashDotDotPattern); /// /// Create a pen with a 'Dash Dot Dot' drawing patterns /// /// The brush. /// The width. + /// The type of the color. /// The Pen - public static Pen DashDotDot(IBrush brush, float width) => new Pen(Pens.DashDotDot(brush, width)); + public static Pen DashDotDot(IBrush brush, float width) + where TPixel : struct, IPixel + => new Pen(brush, width, DashDotDotPattern); } } \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Pens/Pens{TPixel}.cs b/src/ImageSharp.Drawing/Pens/Pens{TPixel}.cs deleted file mode 100644 index 5eb78dc44..000000000 --- a/src/ImageSharp.Drawing/Pens/Pens{TPixel}.cs +++ /dev/null @@ -1,112 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp.Drawing.Pens -{ - using ImageSharp.PixelFormats; - - /// - /// Common Pen styles - /// - /// 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 }; - private static readonly float[] DottedPattern = new[] { 1f, 1f }; - private static readonly float[] DashedPattern = new[] { 3f, 1f }; - - /// - /// Create a solid pen with out any drawing patterns - /// - /// The color. - /// The width. - /// The Pen - public static Pen Solid(TPixel color, float width) - => new Pen(color, width); - - /// - /// Create a solid pen with out any drawing patterns - /// - /// The brush. - /// The width. - /// The Pen - public static Pen Solid(IBrush brush, float width) - => new Pen(brush, width); - - /// - /// Create a pen with a 'Dash' drawing patterns - /// - /// The color. - /// The width. - /// The Pen - public static Pen Dash(TPixel color, float width) - => new Pen(color, width, DashedPattern); - - /// - /// Create a pen with a 'Dash' drawing patterns - /// - /// The brush. - /// The width. - /// The Pen - public static Pen Dash(IBrush brush, float width) - => new Pen(brush, width, DashedPattern); - - /// - /// Create a pen with a 'Dot' drawing patterns - /// - /// The color. - /// The width. - /// The Pen - public static Pen Dot(TPixel color, float width) - => new Pen(color, width, DottedPattern); - - /// - /// Create a pen with a 'Dot' drawing patterns - /// - /// The brush. - /// The width. - /// The Pen - public static Pen Dot(IBrush brush, float width) - => new Pen(brush, width, DottedPattern); - - /// - /// Create a pen with a 'Dash Dot' drawing patterns - /// - /// The color. - /// The width. - /// The Pen - public static Pen DashDot(TPixel color, float width) - => new Pen(color, width, DashDotPattern); - - /// - /// Create a pen with a 'Dash Dot' drawing patterns - /// - /// The brush. - /// The width. - /// The Pen - public static Pen DashDot(IBrush brush, float width) - => new Pen(brush, width, DashDotPattern); - - /// - /// Create a pen with a 'Dash Dot Dot' drawing patterns - /// - /// The color. - /// The width. - /// The Pen - public static Pen DashDotDot(TPixel color, float width) - => new Pen(color, width, DashDotDotPattern); - - /// - /// Create a pen with a 'Dash Dot Dot' drawing patterns - /// - /// The brush. - /// The width. - /// The Pen - 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/Processors/DrawImageProcessor.cs b/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs index c49631de8..ed45417fc 100644 --- a/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs +++ b/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs @@ -8,6 +8,8 @@ namespace ImageSharp.Drawing.Processors using System; using System.Numerics; using System.Threading.Tasks; + + using ImageSharp.Memory; using ImageSharp.PixelFormats; using ImageSharp.Processing; @@ -97,8 +99,8 @@ namespace ImageSharp.Drawing.Processors this.ParallelOptions, y => { - BufferSpan background = sourcePixels.GetRowSpan(y).Slice(minX, width); - BufferSpan foreground = toBlendPixels.GetRowSpan(y - this.Location.Y).Slice(0, width); + Span background = sourcePixels.GetRowSpan(y).Slice(minX, width); + Span foreground = toBlendPixels.GetRowSpan(y - this.Location.Y).Slice(0, width); this.blender.Blend(background, background, foreground, amount); }); } diff --git a/src/ImageSharp.Drawing/Processors/DrawPathProcessor.cs b/src/ImageSharp.Drawing/Processors/DrawPathProcessor.cs index 3fd829549..d1332c435 100644 --- a/src/ImageSharp.Drawing/Processors/DrawPathProcessor.cs +++ b/src/ImageSharp.Drawing/Processors/DrawPathProcessor.cs @@ -8,6 +8,8 @@ namespace ImageSharp.Drawing.Processors using System; using System.Numerics; using System.Threading.Tasks; + + using ImageSharp.Memory; using ImageSharp.PixelFormats; using ImageSharp.Processing; using Pens; @@ -110,7 +112,7 @@ namespace ImageSharp.Drawing.Processors colors[i] = color.Color; } - BufferSpan destination = sourcePixels.GetRowSpan(offsetY).Slice(minX - startX, width); + Span destination = sourcePixels.GetRowSpan(offsetY).Slice(minX - startX, width); blender.Blend(destination, destination, colors, amount); } }); diff --git a/src/ImageSharp.Drawing/Processors/FillProcessor.cs b/src/ImageSharp.Drawing/Processors/FillProcessor.cs index 25eccd245..fa6f48156 100644 --- a/src/ImageSharp.Drawing/Processors/FillProcessor.cs +++ b/src/ImageSharp.Drawing/Processors/FillProcessor.cs @@ -10,6 +10,8 @@ namespace ImageSharp.Drawing.Processors using System.Threading.Tasks; using Drawing; + + using ImageSharp.Memory; using ImageSharp.PixelFormats; using ImageSharp.Processing; diff --git a/src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs b/src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs index 323214fb8..a57be3a5a 100644 --- a/src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs +++ b/src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs @@ -8,6 +8,8 @@ namespace ImageSharp.Drawing.Processors using System; using System.Buffers; using Drawing; + + using ImageSharp.Memory; using ImageSharp.PixelFormats; using ImageSharp.Processing; diff --git a/src/ImageSharp.Drawing/Text/DrawText.cs b/src/ImageSharp.Drawing/Text/DrawText.cs index 1e87fd008..bd33289fa 100644 --- a/src/ImageSharp.Drawing/Text/DrawText.cs +++ b/src/ImageSharp.Drawing/Text/DrawText.cs @@ -54,7 +54,7 @@ namespace ImageSharp 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); } /// diff --git a/src/ImageSharp/Common/Helpers/DebugGuard.cs b/src/ImageSharp/Common/Helpers/DebugGuard.cs index c1fa46191..f6941fc6f 100644 --- a/src/ImageSharp/Common/Helpers/DebugGuard.cs +++ b/src/ImageSharp/Common/Helpers/DebugGuard.cs @@ -159,5 +159,45 @@ namespace ImageSharp throw new ArgumentException(message, parameterName); } } + + /// + /// Verifies, that the target span is of same size than the 'other' span. + /// + /// The element type of the spans + /// The target span. + /// The 'other' span to compare 'target' to. + /// The name of the parameter that is to be checked. + /// + /// is true + /// + [Conditional("DEBUG")] + public static void MustBeSameSized(Span target, Span other, string parameterName) + where T : struct + { + if (target.Length != other.Length) + { + throw new ArgumentException("Span-s must be the same size!", parameterName); + } + } + + /// + /// Verifies, that the `target` span has the length of 'minSpan', or longer. + /// + /// The element type of the spans + /// The target span. + /// The 'minSpan' span to compare 'target' to. + /// The name of the parameter that is to be checked. + /// + /// is true + /// + [Conditional("DEBUG")] + public static void MustBeSizedAtLeast(Span target, Span minSpan, string parameterName) + where T : struct + { + if (target.Length < minSpan.Length) + { + throw new ArgumentException($"Span-s must be at least of length {minSpan.Length}!", parameterName); + } + } } } \ No newline at end of file diff --git a/src/ImageSharp/Common/Helpers/Guard.cs b/src/ImageSharp/Common/Helpers/Guard.cs index cf307e936..a4b392fcf 100644 --- a/src/ImageSharp/Common/Helpers/Guard.cs +++ b/src/ImageSharp/Common/Helpers/Guard.cs @@ -230,5 +230,24 @@ namespace ImageSharp throw new ArgumentException(message, parameterName); } } + + /// + /// Verifies, that the `target` span has the length of 'minSpan', or longer. + /// + /// The element type of the spans + /// The target span. + /// The minimum length. + /// The name of the parameter that is to be checked. + /// + /// is true + /// + public static void MustBeSizedAtLeast(Span target, int minLength, string parameterName) + where T : struct + { + if (target.Length < minLength) + { + throw new ArgumentException($"Span-s must be at least of length {minLength}!", parameterName); + } + } } } diff --git a/src/ImageSharp/Common/Helpers/ImageMaths.cs b/src/ImageSharp/Common/Helpers/ImageMaths.cs index cff9fc04e..6c8c62039 100644 --- a/src/ImageSharp/Common/Helpers/ImageMaths.cs +++ b/src/ImageSharp/Common/Helpers/ImageMaths.cs @@ -146,7 +146,7 @@ namespace ImageSharp /// than the given one. /// /// The pixel format. - /// The to search within. + /// The to search within. /// The color component value to remove. /// The channel to test against. /// diff --git a/src/ImageSharp/Common/Memory/BufferSpan{T}.cs b/src/ImageSharp/Common/Memory/BufferSpan{T}.cs deleted file mode 100644 index 1b0bef314..000000000 --- a/src/ImageSharp/Common/Memory/BufferSpan{T}.cs +++ /dev/null @@ -1,205 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp -{ - using System; - using System.Diagnostics; - using System.Runtime.CompilerServices; - using System.Runtime.InteropServices; - - /// - /// Represents a contiguous region of a pinned managed array. - /// The array is usually owned by a instance. - /// - /// - /// is very similar to corefx System.Span<T>, and we try to maintain a compatible API. - /// There are several differences though: - /// - It's not possible to use it with stack objects or pointers to unmanaged memory, only with managed arrays. - /// - It's possible to retrieve a reference to the array () so we can pass it to API-s like - /// - It's possible to retrieve the pinned pointer. This enables optimized (unchecked) unsafe operations. - /// - There is no bounds checking for performance reasons, only in debug mode. This makes an unsafe type! - /// - /// The type of elements of the array - internal unsafe struct BufferSpan - where T : struct - { - /// - /// Initializes a new instance of the struct from a pinned array and an start. - /// - /// The pinned array - /// The index at which to begin the span. - /// The length - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public BufferSpan(T[] array, int start, int length) - { - GuardArray(array); - - DebugGuard.MustBeLessThanOrEqualTo(start, array.Length, nameof(start)); - DebugGuard.MustBeLessThanOrEqualTo(length, array.Length - start, nameof(length)); - - this.Array = array; - this.Length = length; - this.Start = start; - } - - /// - /// Initializes a new instance of the struct from a pinned array and an start. - /// - /// The pinned array - /// The index at which to begin the span. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public BufferSpan(T[] array, int start) - { - GuardArray(array); - DebugGuard.MustBeLessThanOrEqualTo(start, array.Length, nameof(start)); - - this.Array = array; - this.Length = array.Length - start; - this.Start = start; - } - - /// - /// Initializes a new instance of the struct from a pinned array. - /// - /// The pinned array - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public BufferSpan(T[] array) - { - GuardArray(array); - - this.Array = array; - this.Start = 0; - this.Length = array.Length; - } - - /// - /// Gets the backing array. - /// - public T[] Array { get; private set; } - - /// - /// Gets the length of the - /// - public int Length { get; private set; } - - /// - /// Gets the start inside - /// - public int Start { get; private set; } - - /// - /// Gets the start inside in bytes. - /// - public int ByteOffset => this.Start * Unsafe.SizeOf(); - - /// - /// Returns a reference to specified element of the span. - /// - /// The index - /// The reference to the specified element - public ref T this[int index] - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - DebugGuard.MustBeLessThan(index, this.Length, nameof(index)); - ref T startRef = ref this.DangerousGetPinnableReference(); - return ref Unsafe.Add(ref startRef, index); - } - } - - /// - /// Converts generic to a of bytes - /// setting it's and to correct values. - /// - /// The span of bytes - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public BufferSpan AsBytes() - { - BufferSpan result = default(BufferSpan); - result.Array = Unsafe.As(this.Array); - result.Start = this.Start * Unsafe.SizeOf(); - result.Length = this.Length * Unsafe.SizeOf(); - return result; - } - - /// - /// Returns a reference to the 0th element of the Span. If the Span is empty, returns a reference to the location where the 0th element - /// would have been stored. Such a reference can be used for pinning but must never be dereferenced. - /// - /// The reference to the 0th element - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ref T DangerousGetPinnableReference() - { - ref T origin = ref this.Array[0]; - return ref Unsafe.Add(ref origin, this.Start); - } - - /// - /// Forms a slice out of the given BufferSpan, beginning at 'start'. - /// - /// TThe index at which to begin this slice. - /// The offseted (sliced) BufferSpan - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public BufferSpan Slice(int start) - { - DebugGuard.MustBeLessThan(start, this.Length, nameof(start)); - - BufferSpan result = default(BufferSpan); - result.Array = this.Array; - result.Start = this.Start + start; - result.Length = this.Length - start; - return result; - } - - /// - /// Forms a slice out of the given BufferSpan, beginning at 'start'. - /// - /// The index at which to begin this slice. - /// The desired length for the slice (exclusive). - /// The sliced BufferSpan - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public BufferSpan Slice(int start, int length) - { - DebugGuard.MustBeLessThanOrEqualTo(start, this.Length, nameof(start)); - DebugGuard.MustBeLessThanOrEqualTo(length, this.Length - start, nameof(length)); - - BufferSpan result = default(BufferSpan); - result.Array = this.Array; - result.Start = this.Start + start; - result.Length = length; - return result; - } - - /// - /// Clears `count` elements from the beginning of the span. - /// - /// The number of elements to clear - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Clear(int count) - { - DebugGuard.MustBeLessThanOrEqualTo(count, this.Length, nameof(count)); - - // TODO: Use Unsafe.InitBlock(ref T) for small arrays, when it get's official - System.Array.Clear(this.Array, this.Start, count); - } - - /// - /// Clears the the span - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Clear() - { - this.Clear(this.Length); - } - - [Conditional("DEBUG")] - private static void GuardArray(T[] array) - { - DebugGuard.NotNull(array, nameof(array)); - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/Atkinson.cs b/src/ImageSharp/Dithering/ErrorDiffusion/Atkinson.cs index b94b87255..629944ea1 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/Atkinson.cs +++ b/src/ImageSharp/Dithering/ErrorDiffusion/Atkinson.cs @@ -5,6 +5,8 @@ namespace ImageSharp.Dithering { + using ImageSharp.Memory; + /// /// Applies error diffusion based dithering using the Atkinson image dithering algorithm. /// diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/Burks.cs b/src/ImageSharp/Dithering/ErrorDiffusion/Burks.cs index 894b6e236..02d41c369 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/Burks.cs +++ b/src/ImageSharp/Dithering/ErrorDiffusion/Burks.cs @@ -5,6 +5,8 @@ namespace ImageSharp.Dithering { + using ImageSharp.Memory; + /// /// Applies error diffusion based dithering using the Burks image dithering algorithm. /// diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/ErrorDiffuser.cs b/src/ImageSharp/Dithering/ErrorDiffusion/ErrorDiffuser.cs index 5d0ecde6b..7a5fabdb3 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/ErrorDiffuser.cs +++ b/src/ImageSharp/Dithering/ErrorDiffusion/ErrorDiffuser.cs @@ -8,6 +8,7 @@ namespace ImageSharp.Dithering using System.Numerics; using System.Runtime.CompilerServices; + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/FloydSteinberg.cs b/src/ImageSharp/Dithering/ErrorDiffusion/FloydSteinberg.cs index f7a93667f..6165da634 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/FloydSteinberg.cs +++ b/src/ImageSharp/Dithering/ErrorDiffusion/FloydSteinberg.cs @@ -5,6 +5,8 @@ namespace ImageSharp.Dithering { + using ImageSharp.Memory; + /// /// Applies error diffusion based dithering using the Floyd–Steinberg image dithering algorithm. /// diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/JarvisJudiceNinke.cs b/src/ImageSharp/Dithering/ErrorDiffusion/JarvisJudiceNinke.cs index 60fef8121..6daeab32f 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/JarvisJudiceNinke.cs +++ b/src/ImageSharp/Dithering/ErrorDiffusion/JarvisJudiceNinke.cs @@ -5,6 +5,8 @@ namespace ImageSharp.Dithering { + using ImageSharp.Memory; + /// /// Applies error diffusion based dithering using the JarvisJudiceNinke image dithering algorithm. /// diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/Sierra2.cs b/src/ImageSharp/Dithering/ErrorDiffusion/Sierra2.cs index 4325438e0..0c0944d0e 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/Sierra2.cs +++ b/src/ImageSharp/Dithering/ErrorDiffusion/Sierra2.cs @@ -5,6 +5,8 @@ namespace ImageSharp.Dithering { + using ImageSharp.Memory; + /// /// Applies error diffusion based dithering using the Sierra2 image dithering algorithm. /// diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/Sierra3.cs b/src/ImageSharp/Dithering/ErrorDiffusion/Sierra3.cs index 25ea70d0a..2e2220846 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/Sierra3.cs +++ b/src/ImageSharp/Dithering/ErrorDiffusion/Sierra3.cs @@ -5,6 +5,8 @@ namespace ImageSharp.Dithering { + using ImageSharp.Memory; + /// /// Applies error diffusion based dithering using the Sierra3 image dithering algorithm. /// diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/SierraLite.cs b/src/ImageSharp/Dithering/ErrorDiffusion/SierraLite.cs index c7b1d214f..fe4c933a9 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/SierraLite.cs +++ b/src/ImageSharp/Dithering/ErrorDiffusion/SierraLite.cs @@ -5,6 +5,8 @@ namespace ImageSharp.Dithering { + using ImageSharp.Memory; + /// /// Applies error diffusion based dithering using the SierraLite image dithering algorithm. /// diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/Stucki.cs b/src/ImageSharp/Dithering/ErrorDiffusion/Stucki.cs index 93258c350..b04c16481 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/Stucki.cs +++ b/src/ImageSharp/Dithering/ErrorDiffusion/Stucki.cs @@ -5,6 +5,8 @@ namespace ImageSharp.Dithering { + using ImageSharp.Memory; + /// /// Applies error diffusion based dithering using the Stucki image dithering algorithm. /// diff --git a/src/ImageSharp/Dithering/Ordered/Bayer.cs b/src/ImageSharp/Dithering/Ordered/Bayer.cs index 3792c3c02..ded17d1e1 100644 --- a/src/ImageSharp/Dithering/Ordered/Bayer.cs +++ b/src/ImageSharp/Dithering/Ordered/Bayer.cs @@ -5,6 +5,8 @@ namespace ImageSharp.Dithering.Ordered { + using ImageSharp.Memory; + /// /// Applies error diffusion based dithering using the 4x4 Bayer dithering matrix. /// diff --git a/src/ImageSharp/Dithering/Ordered/Ordered.cs b/src/ImageSharp/Dithering/Ordered/Ordered.cs index ae75b87f2..1fd39eb8b 100644 --- a/src/ImageSharp/Dithering/Ordered/Ordered.cs +++ b/src/ImageSharp/Dithering/Ordered/Ordered.cs @@ -5,6 +5,8 @@ namespace ImageSharp.Dithering.Ordered { + using ImageSharp.Memory; + /// /// Applies error diffusion based dithering using the 4x4 ordered dithering matrix. /// diff --git a/src/ImageSharp/Dithering/Ordered/OrderedDither4x4.cs b/src/ImageSharp/Dithering/Ordered/OrderedDither4x4.cs index 917f57318..48d6c3f6a 100644 --- a/src/ImageSharp/Dithering/Ordered/OrderedDither4x4.cs +++ b/src/ImageSharp/Dithering/Ordered/OrderedDither4x4.cs @@ -5,6 +5,7 @@ namespace ImageSharp.Dithering.Ordered { + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs index a9aac5efa..dd91aa11d 100644 --- a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs @@ -127,7 +127,7 @@ namespace ImageSharp.Formats + $"bigger then the max allowed size '{Image.MaxWidth}x{Image.MaxHeight}'"); } - Image image = Image.Create(this.infoHeader.Width, this.infoHeader.Height, this.configuration); + Image image = new Image(this.configuration, this.infoHeader.Width, this.infoHeader.Height); using (PixelAccessor pixels = image.Lock()) { switch (this.infoHeader.Compression) diff --git a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs index 589b7037a..272e4d075 100644 --- a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs @@ -366,7 +366,7 @@ namespace ImageSharp.Formats 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 = new Image(this.configuration, imageWidth, imageHeight, this.metaData); this.SetFrameMetaData(this.metaData); diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/DecodedBlockArray.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/DecodedBlockArray.cs deleted file mode 100644 index 97a79dd61..000000000 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/DecodedBlockArray.cs +++ /dev/null @@ -1,55 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp.Formats.Jpg -{ - using System; - using System.Buffers; - - /// - /// Because has no information for rented arrays, - /// we need to store the count and the buffer separately when storing pooled arrays. - /// - internal struct DecodedBlockArray : IDisposable - { - /// - /// The used to pool data in . - /// Should always clean arrays when returning! - /// - private static readonly ArrayPool ArrayPool = ArrayPool.Create(); - - /// - /// Initializes a new instance of the struct. Rents a buffer. - /// - /// The number of valid -s - public DecodedBlockArray(int count) - { - this.Count = count; - this.Buffer = ArrayPool.Rent(count); - } - - /// - /// Gets the number of actual -s inside - /// - public int Count { get; } - - /// - /// Gets the rented buffer. - /// - public DecodedBlock[] Buffer { get; private set; } - - /// - /// Returns the rented buffer to the pool. - /// - public void Dispose() - { - if (this.Buffer != null) - { - ArrayPool.Return(this.Buffer, true); - this.Buffer = null; - } - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBlockProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBlockProcessor.cs index 0acee3a10..71472c00f 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBlockProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBlockProcessor.cs @@ -8,8 +8,10 @@ namespace ImageSharp.Formats.Jpg using System.Runtime.CompilerServices; using System.Runtime.InteropServices; + using ImageSharp.Memory; + /// - /// Encapsulates the implementation of processing "raw" -s into Jpeg image channels. + /// Encapsulates the implementation of processing "raw" -s into Jpeg image channels. /// [StructLayout(LayoutKind.Sequential)] internal unsafe struct JpegBlockProcessor @@ -47,10 +49,10 @@ namespace ImageSharp.Formats.Jpg /// The instance public void ProcessAllBlocks(JpegDecoderCore decoder) { - DecodedBlockArray blockArray = decoder.DecodedBlocks[this.componentIndex]; - for (int i = 0; i < blockArray.Count; i++) + Buffer blockArray = decoder.DecodedBlocks[this.componentIndex]; + for (int i = 0; i < blockArray.Length; i++) { - this.ProcessBlockColors(decoder, ref blockArray.Buffer[i]); + this.ProcessBlockColors(decoder, ref blockArray[i]); } } diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegPixelArea.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegPixelArea.cs index 728da8d02..342ce299c 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegPixelArea.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegPixelArea.cs @@ -4,9 +4,10 @@ // namespace ImageSharp.Formats.Jpg { - using System.Buffers; using System.Runtime.CompilerServices; + using ImageSharp.Memory; + /// /// Represents an area of a Jpeg subimage (channel) /// @@ -15,20 +16,30 @@ namespace ImageSharp.Formats.Jpg /// /// Initializes a new instance of the struct from existing data. /// - /// The pixel array - /// The stride + /// The pixel buffer + /// The stride /// The offset - public JpegPixelArea(byte[] pixels, int striede, int offset) + public JpegPixelArea(Buffer2D pixels, int stride, int offset) { - this.Stride = striede; + this.Stride = stride; this.Pixels = pixels; this.Offset = offset; } /// - /// Gets the pixels. + /// Initializes a new instance of the struct from existing buffer. + /// will be set to of and will be set to 0. + /// + /// The pixel buffer + public JpegPixelArea(Buffer2D pixels) + : this(pixels, pixels.Width, 0) + { + } + + /// + /// Gets the pixels buffer. /// - public byte[] Pixels { get; private set; } + public Buffer2D Pixels { get; private set; } /// /// Gets a value indicating whether the instance has been initalized. (Is not default(JpegPixelArea)) @@ -36,21 +47,19 @@ namespace ImageSharp.Formats.Jpg public bool IsInitialized => this.Pixels != null; /// - /// Gets or the stride. + /// Gets the stride. /// public int Stride { get; } /// - /// Gets or the offset. + /// Gets the offset. /// public int Offset { get; } /// /// Gets a of bytes to the pixel area /// - public MutableSpan Span => new MutableSpan(this.Pixels, this.Offset); - - private static ArrayPool BytePool => ArrayPool.Shared; + public MutableSpan Span => new MutableSpan(this.Pixels.Array, this.Offset); /// /// Returns the pixel at (x, y) @@ -67,35 +76,6 @@ namespace ImageSharp.Formats.Jpg } } - /// - /// Creates a new instance of the struct. - /// Pixel array will be taken from a pool, this instance will be the owner of it's pixel data, therefore - /// should be called when the instance is no longer needed. - /// - /// The width. - /// The height. - /// A with pooled data - public static JpegPixelArea CreatePooled(int width, int height) - { - int size = width * height; - byte[] pixels = BytePool.Rent(size); - return new JpegPixelArea(pixels, width, 0); - } - - /// - /// Returns to the pool - /// - public void ReturnPooled() - { - if (this.Pixels == null) - { - return; - } - - BytePool.Return(this.Pixels); - this.Pixels = null; - } - /// /// Gets the subarea that belongs to the Block8x8 defined by block indices /// @@ -129,7 +109,7 @@ namespace ImageSharp.Formats.Jpg public unsafe void LoadColorsFrom(Block8x8F* block, Block8x8F* temp) { // Level shift by +128, clip to [0, 255], and write to dst. - block->CopyColorsTo(new MutableSpan(this.Pixels, this.Offset), this.Stride, temp); + block->CopyColorsTo(new MutableSpan(this.Pixels.Array, this.Offset), this.Stride, temp); } } } \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegScanDecoder.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegScanDecoder.cs index c6362a871..7d2e6d441 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegScanDecoder.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegScanDecoder.cs @@ -9,6 +9,8 @@ namespace ImageSharp.Formats.Jpg using System.Runtime.CompilerServices; using System.Runtime.InteropServices; + using ImageSharp.Memory; + /// /// Encapsulates the impementation of Jpeg SOS Huffman decoding. See JpegScanDecoder.md! /// @@ -171,7 +173,7 @@ namespace ImageSharp.Formats.Jpg // Take an existing block (required when progressive): int blockIndex = this.GetBlockIndex(decoder); - this.data.Block = decoder.DecodedBlocks[this.ComponentIndex].Buffer[blockIndex].Block; + this.data.Block = decoder.DecodedBlocks[this.ComponentIndex][blockIndex].Block; if (!decoder.InputProcessor.UnexpectedEndOfStreamReached) { @@ -179,8 +181,8 @@ namespace ImageSharp.Formats.Jpg } // Store the decoded block - DecodedBlockArray blocks = decoder.DecodedBlocks[this.ComponentIndex]; - blocks.Buffer[blockIndex].SaveBlock(this.bx, this.by, ref this.data.Block); + Buffer blocks = decoder.DecodedBlocks[this.ComponentIndex]; + blocks[blockIndex].SaveBlock(this.bx, this.by, ref this.data.Block); } // for j diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/YCbCrImage.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/YCbCrImage.cs index a5ca9796b..89e327f0d 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/YCbCrImage.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/YCbCrImage.cs @@ -7,6 +7,8 @@ namespace ImageSharp.Formats.Jpg using System; using System.Buffers; + using ImageSharp.Memory; + /// /// Represents an image made up of three color components (luminance, blue chroma, red chroma) /// @@ -17,17 +19,17 @@ namespace ImageSharp.Formats.Jpg /// /// Gets the luminance components channel as . /// - public JpegPixelArea YChannel; + public Buffer2D YChannel; /// /// Gets the blue chroma components channel as . /// - public JpegPixelArea CbChannel; + public Buffer2D CbChannel; /// /// Gets an offseted to the Cr channel /// - public JpegPixelArea CrChannel; + public Buffer2D CrChannel; #pragma warning restore SA1401 /// @@ -44,9 +46,9 @@ namespace ImageSharp.Formats.Jpg this.YStride = width; this.CStride = cSize.Width; - this.YChannel = JpegPixelArea.CreatePooled(width, height); - this.CbChannel = JpegPixelArea.CreatePooled(cSize.Width, cSize.Height); - this.CrChannel = JpegPixelArea.CreatePooled(cSize.Width, cSize.Height); + this.YChannel = Buffer2D.CreateClean(width, height); + this.CbChannel = Buffer2D.CreateClean(cSize.Width, cSize.Height); + this.CrChannel = Buffer2D.CreateClean(cSize.Width, cSize.Height); } /// @@ -106,9 +108,9 @@ namespace ImageSharp.Formats.Jpg /// public void Dispose() { - this.YChannel.ReturnPooled(); - this.CbChannel.ReturnPooled(); - this.CrChannel.ReturnPooled(); + this.YChannel.Dispose(); + this.CbChannel.Dispose(); + this.CrChannel.Dispose(); } /// diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs index 55335945b..fc2a9130e 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs @@ -12,6 +12,7 @@ namespace ImageSharp.Formats using System.Threading.Tasks; using ImageSharp.Formats.Jpg; + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// @@ -112,7 +113,7 @@ namespace ImageSharp.Formats this.QuantizationTables = new Block8x8F[MaxTq + 1]; this.Temp = new byte[2 * Block8x8F.ScalarCount]; this.ComponentArray = new Component[MaxComponents]; - this.DecodedBlocks = new DecodedBlockArray[MaxComponents]; + this.DecodedBlocks = new Buffer[MaxComponents]; } /// @@ -126,12 +127,12 @@ namespace ImageSharp.Formats public HuffmanTree[] HuffmanTrees { get; } /// - /// Gets the array of -s storing the "raw" frequency-domain decoded blocks. + /// 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 . /// When ==true, we are touching these blocks multiple times - each time we process a Scan. /// - public DecodedBlockArray[] DecodedBlocks { get; } + public Buffer[] DecodedBlocks { get; } /// /// Gets the quantization tables, in zigzag order. @@ -217,15 +218,15 @@ namespace ImageSharp.Formats this.HuffmanTrees[i].Dispose(); } - foreach (DecodedBlockArray blockArray in this.DecodedBlocks) + foreach (Buffer blockArray in this.DecodedBlocks) { - blockArray.Dispose(); + blockArray?.Dispose(); } this.ycbcrImage?.Dispose(); this.InputProcessor.Dispose(); - this.grayImage.ReturnPooled(); - this.blackImage.ReturnPooled(); + this.grayImage.Pixels?.Dispose(); + this.blackImage.Pixels?.Dispose(); } /// @@ -244,11 +245,11 @@ namespace ImageSharp.Formats switch (compIndex) { case 0: - return this.ycbcrImage.YChannel; + return new JpegPixelArea(this.ycbcrImage.YChannel); case 1: - return this.ycbcrImage.CbChannel; + return new JpegPixelArea(this.ycbcrImage.CbChannel); case 2: - return this.ycbcrImage.CrChannel; + return new JpegPixelArea(this.ycbcrImage.CrChannel); case 3: return this.blackImage; default: @@ -486,7 +487,7 @@ namespace ImageSharp.Formats private Image ConvertJpegPixelsToImagePixels(ImageMetaData metadata) where TPixel : struct, IPixel { - Image image = Image.Create(this.ImageWidth, this.ImageHeight, metadata, this.configuration); + Image image = new Image(this.configuration, this.ImageWidth, this.ImageHeight, metadata); if (this.grayImage.IsInitialized) { @@ -590,9 +591,9 @@ namespace ImageSharp.Formats for (int x = 0; x < image.Width; x++) { - byte cyan = this.ycbcrImage.YChannel.Pixels[yo + x]; - byte magenta = this.ycbcrImage.CbChannel.Pixels[co + (x / scale)]; - byte yellow = this.ycbcrImage.CrChannel.Pixels[co + (x / scale)]; + byte cyan = this.ycbcrImage.YChannel[yo + x]; + byte magenta = this.ycbcrImage.CbChannel[co + (x / scale)]; + byte yellow = this.ycbcrImage.CrChannel[co + (x / scale)]; TPixel packed = default(TPixel); this.PackCmyk(ref packed, cyan, magenta, yellow, x, y); @@ -659,9 +660,9 @@ namespace ImageSharp.Formats for (int x = 0; x < image.Width; x++) { - byte red = this.ycbcrImage.YChannel.Pixels[yo + x]; - byte green = this.ycbcrImage.CbChannel.Pixels[co + (x / scale)]; - byte blue = this.ycbcrImage.CrChannel.Pixels[co + (x / scale)]; + byte red = this.ycbcrImage.YChannel[yo + x]; + byte green = this.ycbcrImage.CbChannel[co + (x / scale)]; + byte blue = this.ycbcrImage.CrChannel[co + (x / scale)]; TPixel packed = default(TPixel); packed.PackFromBytes(red, green, blue, 255); @@ -691,9 +692,9 @@ namespace ImageSharp.Formats y => { // TODO. This Parallel loop doesn't give us the boost it should. - ref byte ycRef = ref this.ycbcrImage.YChannel.Pixels[0]; - ref byte cbRef = ref this.ycbcrImage.CbChannel.Pixels[0]; - ref byte crRef = ref this.ycbcrImage.CrChannel.Pixels[0]; + ref byte ycRef = ref this.ycbcrImage.YChannel[0]; + ref byte cbRef = ref this.ycbcrImage.CbChannel[0]; + ref byte crRef = ref this.ycbcrImage.CrChannel[0]; fixed (YCbCrToRgbTables* tables = &yCbCrToRgbTables) { // TODO: Simplify + optimize + share duplicate code across converter methods @@ -741,9 +742,9 @@ namespace ImageSharp.Formats for (int x = 0; x < image.Width; x++) { - byte yy = this.ycbcrImage.YChannel.Pixels[yo + x]; - byte cb = this.ycbcrImage.CbChannel.Pixels[co + (x / scale)]; - byte cr = this.ycbcrImage.CrChannel.Pixels[co + (x / scale)]; + byte yy = this.ycbcrImage.YChannel[yo + x]; + byte cb = this.ycbcrImage.CbChannel[co + (x / scale)]; + byte cr = this.ycbcrImage.CrChannel[co + (x / scale)]; TPixel packed = default(TPixel); this.PackYcck(ref packed, yy, cb, cr, x, y); @@ -791,7 +792,8 @@ namespace ImageSharp.Formats if (this.ComponentCount == 1) { - this.grayImage = JpegPixelArea.CreatePooled(8 * this.MCUCountX, 8 * this.MCUCountY); + Buffer2D buffer = Buffer2D.CreateClean(8 * this.MCUCountX, 8 * this.MCUCountY); + this.grayImage = new JpegPixelArea(buffer); } else { @@ -830,7 +832,8 @@ namespace ImageSharp.Formats int h3 = this.ComponentArray[3].HorizontalFactor; int v3 = this.ComponentArray[3].VerticalFactor; - this.blackImage = JpegPixelArea.CreatePooled(8 * h3 * this.MCUCountX, 8 * v3 * this.MCUCountY); + Buffer2D buffer = Buffer2D.CreateClean(8 * h3 * this.MCUCountX, 8 * v3 * this.MCUCountY); + this.blackImage = new JpegPixelArea(buffer); } } } @@ -1358,7 +1361,7 @@ namespace ImageSharp.Formats { int count = this.TotalMCUCount * this.ComponentArray[i].HorizontalFactor * this.ComponentArray[i].VerticalFactor; - this.DecodedBlocks[i] = new DecodedBlockArray(count); + this.DecodedBlocks[i] = Buffer.CreateClean(count); } } } diff --git a/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs b/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs index b4ec49946..db2189b3c 100644 --- a/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs +++ b/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs @@ -5,6 +5,7 @@ namespace ImageSharp.Formats { + using System; using System.Runtime.CompilerServices; /// @@ -12,28 +13,37 @@ namespace ImageSharp.Formats /// the value of a pixel. /// /// - internal static unsafe class AverageFilter + internal static class AverageFilter { /// /// Decodes the scanline /// /// The scanline to decode /// The previous scanline. - /// The number of bytes per scanline /// The bytes per pixel. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Decode(byte[] scanline, byte[] previousScanline, int bytesPerScanline, int bytesPerPixel) + public static void Decode(Span scanline, Span previousScanline, int bytesPerPixel) { + DebugGuard.MustBeSameSized(scanline, previousScanline, nameof(scanline)); + + ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference(); + ref byte prevBaseRef = ref previousScanline.DangerousGetPinnableReference(); + // Average(x) + floor((Raw(x-bpp)+Prior(x))/2) - fixed (byte* scan = scanline) - fixed (byte* prev = previousScanline) + for (int x = 1; x < scanline.Length; x++) { - for (int x = 1; x < bytesPerScanline; x++) + if (x - bytesPerPixel < 1) { - byte left = (x - bytesPerPixel < 1) ? (byte)0 : scan[x - bytesPerPixel]; - byte above = prev[x]; - - scan[x] = (byte)((scan[x] + Average(left, above)) % 256); + ref byte scan = ref Unsafe.Add(ref scanBaseRef, x); + byte above = Unsafe.Add(ref prevBaseRef, x); + scan = (byte)((scan + (above >> 1)) % 256); + } + else + { + ref byte scan = ref Unsafe.Add(ref scanBaseRef, x); + byte left = Unsafe.Add(ref scanBaseRef, x - bytesPerPixel); + byte above = Unsafe.Add(ref prevBaseRef, x); + scan = (byte)((scan + Average(left, above)) % 256); } } } @@ -46,21 +56,34 @@ namespace ImageSharp.Formats /// The filtered scanline result. /// The bytes per pixel. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Encode(byte[] scanline, byte[] previousScanline, byte[] result, int bytesPerPixel) + public static void Encode(Span scanline, Span previousScanline, Span result, int bytesPerPixel) { + DebugGuard.MustBeSameSized(scanline, previousScanline, nameof(scanline)); + DebugGuard.MustBeSizedAtLeast(result, scanline, nameof(result)); + + ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference(); + ref byte prevBaseRef = ref previousScanline.DangerousGetPinnableReference(); + ref byte resultBaseRef = ref result.DangerousGetPinnableReference(); + // Average(x) = Raw(x) - floor((Raw(x-bpp)+Prior(x))/2) - fixed (byte* scan = scanline) - fixed (byte* prev = previousScanline) - fixed (byte* res = result) - { - res[0] = 3; + resultBaseRef = 3; - for (int x = 0; x < scanline.Length; x++) + for (int x = 0; x < scanline.Length; x++) + { + if (x - bytesPerPixel < 0) { - byte left = (x - bytesPerPixel < 0) ? (byte)0 : scan[x - bytesPerPixel]; - byte above = prev[x]; - - res[x + 1] = (byte)((scan[x] - Average(left, above)) % 256); + byte scan = Unsafe.Add(ref scanBaseRef, x); + byte above = Unsafe.Add(ref prevBaseRef, x); + ref byte res = ref Unsafe.Add(ref resultBaseRef, x + 1); + res = (byte)((scan - (above >> 1)) % 256); + } + else + { + byte scan = Unsafe.Add(ref scanBaseRef, x); + byte left = Unsafe.Add(ref scanBaseRef, x - bytesPerPixel); + byte above = Unsafe.Add(ref prevBaseRef, x); + ref byte res = ref Unsafe.Add(ref resultBaseRef, x + 1); + res = (byte)((scan - Average(left, above)) % 256); } } } diff --git a/src/ImageSharp/Formats/Png/Filters/NoneFilter.cs b/src/ImageSharp/Formats/Png/Filters/NoneFilter.cs index 5abd89296..ee77d1a5e 100644 --- a/src/ImageSharp/Formats/Png/Filters/NoneFilter.cs +++ b/src/ImageSharp/Formats/Png/Filters/NoneFilter.cs @@ -8,6 +8,8 @@ namespace ImageSharp.Formats using System; using System.Runtime.CompilerServices; + using ImageSharp.Memory; + /// /// The None filter, the scanline is transmitted unmodified; it is only necessary to /// insert a filter type byte before the data. @@ -15,29 +17,18 @@ namespace ImageSharp.Formats /// internal static class NoneFilter { - /// - /// Decodes the scanline - /// - /// The scanline to decode - /// The - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static byte[] Decode(byte[] scanline) - { - // No change required. - return scanline; - } - /// /// Encodes the scanline /// /// The scanline to encode /// The filtered scanline result. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Encode(byte[] scanline, byte[] result) + public static void Encode(Span scanline, Span result) { // Insert a byte before the data. result[0] = 0; - Buffer.BlockCopy(scanline, 0, result, 1, scanline.Length); + result = result.Slice(1); + SpanHelper.Copy(scanline, result); } } } diff --git a/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs b/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs index a43d4f080..ec12eca05 100644 --- a/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs +++ b/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs @@ -21,22 +21,31 @@ namespace ImageSharp.Formats /// /// The scanline to decode /// The previous scanline. - /// The number of bytes per scanline /// The bytes per pixel. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Decode(byte[] scanline, byte[] previousScanline, int bytesPerScanline, int bytesPerPixel) + public static void Decode(Span scanline, Span previousScanline, int bytesPerPixel) { + DebugGuard.MustBeSameSized(scanline, previousScanline, nameof(scanline)); + + ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference(); + ref byte prevBaseRef = ref previousScanline.DangerousGetPinnableReference(); + // Paeth(x) + PaethPredictor(Raw(x-bpp), Prior(x), Prior(x-bpp)) - fixed (byte* scan = scanline) - fixed (byte* prev = previousScanline) + for (int x = 1; x < scanline.Length; x++) { - for (int x = 1; x < bytesPerScanline; x++) + if (x - bytesPerPixel < 1) { - byte left = (x - bytesPerPixel < 1) ? (byte)0 : scan[x - bytesPerPixel]; - byte above = prev[x]; - byte upperLeft = (x - bytesPerPixel < 1) ? (byte)0 : prev[x - bytesPerPixel]; - - scan[x] = (byte)((scan[x] + PaethPredicator(left, above, upperLeft)) % 256); + ref byte scan = ref Unsafe.Add(ref scanBaseRef, x); + byte above = Unsafe.Add(ref prevBaseRef, x); + scan = (byte)((scan + PaethPredicator(0, above, 0)) % 256); + } + else + { + ref byte scan = ref Unsafe.Add(ref scanBaseRef, x); + byte left = Unsafe.Add(ref scanBaseRef, x - bytesPerPixel); + byte above = Unsafe.Add(ref prevBaseRef, x); + byte upperLeft = Unsafe.Add(ref prevBaseRef, x - bytesPerPixel); + scan = (byte)((scan + PaethPredicator(left, above, upperLeft)) % 256); } } } @@ -49,22 +58,35 @@ namespace ImageSharp.Formats /// The filtered scanline result. /// The bytes per pixel. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Encode(byte[] scanline, byte[] previousScanline, byte[] result, int bytesPerPixel) + public static void Encode(Span scanline, Span previousScanline, Span result, int bytesPerPixel) { + DebugGuard.MustBeSameSized(scanline, previousScanline, nameof(scanline)); + DebugGuard.MustBeSizedAtLeast(result, scanline, nameof(result)); + + ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference(); + ref byte prevBaseRef = ref previousScanline.DangerousGetPinnableReference(); + ref byte resultBaseRef = ref result.DangerousGetPinnableReference(); + // Paeth(x) = Raw(x) - PaethPredictor(Raw(x-bpp), Prior(x), Prior(x - bpp)) - fixed (byte* scan = scanline) - fixed (byte* prev = previousScanline) - fixed (byte* res = result) - { - res[0] = 4; + resultBaseRef = 4; - for (int x = 0; x < scanline.Length; x++) + for (int x = 0; x < scanline.Length; x++) + { + if (x - bytesPerPixel < 0) { - byte left = (x - bytesPerPixel < 0) ? (byte)0 : scan[x - bytesPerPixel]; - byte above = prev[x]; - byte upperLeft = (x - bytesPerPixel < 0) ? (byte)0 : prev[x - bytesPerPixel]; - - res[x + 1] = (byte)((scan[x] - PaethPredicator(left, above, upperLeft)) % 256); + byte scan = Unsafe.Add(ref scanBaseRef, x); + byte above = Unsafe.Add(ref prevBaseRef, x); + ref byte res = ref Unsafe.Add(ref resultBaseRef, x + 1); + res = (byte)((scan - PaethPredicator(0, above, 0)) % 256); + } + else + { + byte scan = Unsafe.Add(ref scanBaseRef, x); + byte left = Unsafe.Add(ref scanBaseRef, x - bytesPerPixel); + byte above = Unsafe.Add(ref prevBaseRef, x); + byte upperLeft = Unsafe.Add(ref prevBaseRef, x - bytesPerPixel); + ref byte res = ref Unsafe.Add(ref resultBaseRef, x + 1); + res = (byte)((scan - PaethPredicator(left, above, upperLeft)) % 256); } } } @@ -100,4 +122,4 @@ namespace ImageSharp.Formats return upperLeft; } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Png/Filters/SubFilter.cs b/src/ImageSharp/Formats/Png/Filters/SubFilter.cs index 4610ed0ae..f81122ad2 100644 --- a/src/ImageSharp/Formats/Png/Filters/SubFilter.cs +++ b/src/ImageSharp/Formats/Png/Filters/SubFilter.cs @@ -5,6 +5,7 @@ namespace ImageSharp.Formats { + using System; using System.Runtime.CompilerServices; /// @@ -18,18 +19,25 @@ namespace ImageSharp.Formats /// Decodes the scanline /// /// The scanline to decode - /// The number of bytes per scanline /// The bytes per pixel. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Decode(byte[] scanline, int bytesPerScanline, int bytesPerPixel) + public static void Decode(Span scanline, int bytesPerPixel) { + ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference(); + // Sub(x) + Raw(x-bpp) - fixed (byte* scan = scanline) + for (int x = 1; x < scanline.Length; x++) { - for (int x = 1; x < bytesPerScanline; x++) + if (x - bytesPerPixel < 1) + { + ref byte scan = ref Unsafe.Add(ref scanBaseRef, x); + scan = (byte)(scan % 256); + } + else { - byte priorRawByte = (x - bytesPerPixel < 1) ? (byte)0 : scan[x - bytesPerPixel]; - scan[x] = (byte)((scan[x] + priorRawByte) % 256); + ref byte scan = ref Unsafe.Add(ref scanBaseRef, x); + byte prev = Unsafe.Add(ref scanBaseRef, x - bytesPerPixel); + scan = (byte)((scan + prev) % 256); } } } @@ -41,19 +49,30 @@ namespace ImageSharp.Formats /// The filtered scanline result. /// The bytes per pixel. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Encode(byte[] scanline, byte[] result, int bytesPerPixel) + public static void Encode(Span scanline, Span result, int bytesPerPixel) { + DebugGuard.MustBeSizedAtLeast(result, scanline, nameof(result)); + + ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference(); + ref byte resultBaseRef = ref result.DangerousGetPinnableReference(); + // Sub(x) = Raw(x) - Raw(x-bpp) - fixed (byte* scan = scanline) - fixed (byte* res = result) - { - res[0] = 1; + resultBaseRef = 1; - for (int x = 0; x < scanline.Length; x++) + for (int x = 0; x < scanline.Length; x++) + { + if (x - bytesPerPixel < 0) { - byte priorRawByte = (x - bytesPerPixel < 0) ? (byte)0 : scan[x - bytesPerPixel]; - - res[x + 1] = (byte)((scan[x] - priorRawByte) % 256); + byte scan = Unsafe.Add(ref scanBaseRef, x); + ref byte res = ref Unsafe.Add(ref resultBaseRef, x + 1); + res = (byte)(scan % 256); + } + else + { + byte scan = Unsafe.Add(ref scanBaseRef, x); + byte prev = Unsafe.Add(ref scanBaseRef, x - bytesPerPixel); + ref byte res = ref Unsafe.Add(ref resultBaseRef, x + 1); + res = (byte)((scan - prev) % 256); } } } diff --git a/src/ImageSharp/Formats/Png/Filters/UpFilter.cs b/src/ImageSharp/Formats/Png/Filters/UpFilter.cs index 525f50d0f..b89a3c5fc 100644 --- a/src/ImageSharp/Formats/Png/Filters/UpFilter.cs +++ b/src/ImageSharp/Formats/Png/Filters/UpFilter.cs @@ -5,6 +5,7 @@ namespace ImageSharp.Formats { + using System; using System.Runtime.CompilerServices; /// @@ -19,20 +20,20 @@ namespace ImageSharp.Formats /// /// The scanline to decode /// The previous scanline. - /// The number of bytes per scanline [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Decode(byte[] scanline, byte[] previousScanline, int bytesPerScanline) + public static void Decode(Span scanline, Span previousScanline) { + DebugGuard.MustBeSameSized(scanline, previousScanline, nameof(scanline)); + + ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference(); + ref byte prevBaseRef = ref previousScanline.DangerousGetPinnableReference(); + // Up(x) + Prior(x) - fixed (byte* scan = scanline) - fixed (byte* prev = previousScanline) + for (int x = 1; x < scanline.Length; x++) { - for (int x = 1; x < bytesPerScanline; x++) - { - byte above = prev[x]; - - scan[x] = (byte)((scan[x] + above) % 256); - } + ref byte scan = ref Unsafe.Add(ref scanBaseRef, x); + byte above = Unsafe.Add(ref prevBaseRef, x); + scan = (byte)((scan + above) % 256); } } @@ -43,21 +44,24 @@ namespace ImageSharp.Formats /// The previous scanline. /// The filtered scanline result. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Encode(byte[] scanline, byte[] previousScanline, byte[] result) + public static void Encode(Span scanline, Span previousScanline, Span result) { - // Up(x) = Raw(x) - Prior(x) - fixed (byte* scan = scanline) - fixed (byte* prev = previousScanline) - fixed (byte* res = result) - { - res[0] = 2; + DebugGuard.MustBeSameSized(scanline, previousScanline, nameof(scanline)); + DebugGuard.MustBeSizedAtLeast(result, scanline, nameof(result)); + + ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference(); + ref byte prevBaseRef = ref previousScanline.DangerousGetPinnableReference(); + ref byte resultBaseRef = ref result.DangerousGetPinnableReference(); - for (int x = 0; x < scanline.Length; x++) - { - byte above = prev[x]; + // Up(x) = Raw(x) - Prior(x) + resultBaseRef = 2; - res[x + 1] = (byte)((scan[x] - above) % 256); - } + for (int x = 0; x < scanline.Length; x++) + { + byte scan = Unsafe.Add(ref scanBaseRef, x); + byte above = Unsafe.Add(ref prevBaseRef, x); + ref byte res = ref Unsafe.Add(ref resultBaseRef, x + 1); + res = (byte)((scan - above) % 256); } } } diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index 904aa1ff6..f8be0f6cc 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -12,6 +12,7 @@ namespace ImageSharp.Formats using System.Linq; using System.Runtime.CompilerServices; + using ImageSharp.Memory; using ImageSharp.PixelFormats; using static ComparableExtensions; @@ -131,12 +132,12 @@ namespace ImageSharp.Formats /// /// Previous scanline processed /// - private byte[] previousScanline; + private Buffer previousScanline; /// /// The current scanline that is being processed /// - private byte[] scanline; + private Buffer scanline; /// /// The index of the current scanline being processed @@ -184,14 +185,14 @@ namespace ImageSharp.Formats public Image Decode(Stream stream) where TPixel : struct, IPixel { - ImageMetaData metadata = new ImageMetaData(); + var metadata = new ImageMetaData(); this.currentStream = stream; this.currentStream.Skip(8); Image image = null; PixelAccessor pixels = null; try { - using (ZlibInflateStream deframeStream = new ZlibInflateStream(this.currentStream)) + using (var deframeStream = new ZlibInflateStream(this.currentStream)) { PngChunk currentChunk; while (!this.isEndChunkReached && (currentChunk = this.ReadChunk()) != null) @@ -252,11 +253,8 @@ namespace ImageSharp.Formats finally { pixels?.Dispose(); - if (this.previousScanline != null) - { - ArrayPool.Shared.Return(this.previousScanline); - ArrayPool.Shared.Return(this.scanline); - } + this.scanline?.Dispose(); + this.previousScanline?.Dispose(); } } @@ -335,7 +333,7 @@ namespace ImageSharp.Formats 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.Create(this.header.Width, this.header.Height, metadata, this.configuration); + image = new Image(this.configuration, this.header.Width, this.header.Height, metadata); pixels = image.Lock(); this.bytesPerPixel = this.CalculateBytesPerPixel(); this.bytesPerScanline = this.CalculateScanlineLength(this.header.Width) + 1; @@ -345,12 +343,8 @@ namespace ImageSharp.Formats this.bytesPerSample = this.header.BitDepth / 8; } - this.previousScanline = ArrayPool.Shared.Rent(this.bytesPerScanline); - this.scanline = ArrayPool.Shared.Rent(this.bytesPerScanline); - - // Zero out the scanlines, because the bytes that are rented from the arraypool may not be zero. - Array.Clear(this.scanline, 0, this.bytesPerScanline); - Array.Clear(this.previousScanline, 0, this.bytesPerScanline); + this.previousScanline = Buffer.CreateClean(this.bytesPerScanline); + this.scanline = Buffer.CreateClean(this.bytesPerScanline); } /// @@ -429,7 +423,7 @@ namespace ImageSharp.Formats { while (this.currentRow < this.header.Height) { - int bytesRead = compressedStream.Read(this.scanline, this.currentRowBytesRead, this.bytesPerScanline - this.currentRowBytesRead); + int bytesRead = compressedStream.Read(this.scanline.Array, this.currentRowBytesRead, this.bytesPerScanline - this.currentRowBytesRead); this.currentRowBytesRead += bytesRead; if (this.currentRowBytesRead < this.bytesPerScanline) { @@ -437,45 +431,38 @@ namespace ImageSharp.Formats } this.currentRowBytesRead = 0; - FilterType filterType = (FilterType)this.scanline[0]; + var filterType = (FilterType)this.scanline[0]; switch (filterType) { case FilterType.None: - - NoneFilter.Decode(this.scanline); - break; case FilterType.Sub: - SubFilter.Decode(this.scanline, this.bytesPerScanline, this.bytesPerPixel); - + SubFilter.Decode(this.scanline, this.bytesPerPixel); break; case FilterType.Up: - UpFilter.Decode(this.scanline, this.previousScanline, this.bytesPerScanline); - + UpFilter.Decode(this.scanline, this.previousScanline); break; case FilterType.Average: - AverageFilter.Decode(this.scanline, this.previousScanline, this.bytesPerScanline, this.bytesPerPixel); - + AverageFilter.Decode(this.scanline, this.previousScanline, this.bytesPerPixel); break; case FilterType.Paeth: - PaethFilter.Decode(this.scanline, this.previousScanline, this.bytesPerScanline, this.bytesPerPixel); - + PaethFilter.Decode(this.scanline, this.previousScanline, this.bytesPerPixel); break; default: throw new ImageFormatException("Unknown filter type."); } - this.ProcessDefilteredScanline(this.scanline, pixels); + this.ProcessDefilteredScanline(this.scanline.Array, pixels); Swap(ref this.scanline, ref this.previousScanline); this.currentRow++; @@ -508,7 +495,7 @@ namespace ImageSharp.Formats while (this.currentRow < this.header.Height) { - int bytesRead = compressedStream.Read(this.scanline, this.currentRowBytesRead, bytesPerInterlaceScanline - this.currentRowBytesRead); + int bytesRead = compressedStream.Read(this.scanline.Array, this.currentRowBytesRead, bytesPerInterlaceScanline - this.currentRowBytesRead); this.currentRowBytesRead += bytesRead; if (this.currentRowBytesRead < bytesPerInterlaceScanline) { @@ -517,45 +504,40 @@ namespace ImageSharp.Formats this.currentRowBytesRead = 0; - FilterType filterType = (FilterType)this.scanline[0]; + Span scanSpan = this.scanline.Slice(0, bytesPerInterlaceScanline); + Span prevSpan = this.previousScanline.Span.Slice(0, bytesPerInterlaceScanline); + var filterType = (FilterType)scanSpan[0]; switch (filterType) { case FilterType.None: - - NoneFilter.Decode(this.scanline); - break; case FilterType.Sub: - SubFilter.Decode(this.scanline, bytesPerInterlaceScanline, this.bytesPerPixel); - + SubFilter.Decode(scanSpan, this.bytesPerPixel); break; case FilterType.Up: - UpFilter.Decode(this.scanline, this.previousScanline, bytesPerInterlaceScanline); - + UpFilter.Decode(scanSpan, prevSpan); break; case FilterType.Average: - AverageFilter.Decode(this.scanline, this.previousScanline, bytesPerInterlaceScanline, this.bytesPerPixel); - + AverageFilter.Decode(scanSpan, prevSpan, this.bytesPerPixel); break; case FilterType.Paeth: - PaethFilter.Decode(this.scanline, this.previousScanline, bytesPerInterlaceScanline, this.bytesPerPixel); - + PaethFilter.Decode(scanSpan, prevSpan, this.bytesPerPixel); break; default: throw new ImageFormatException("Unknown filter type."); } - this.ProcessInterlacedDefilteredScanline(this.scanline, this.currentRow, pixels, Adam7FirstColumn[this.pass], Adam7ColumnIncrement[this.pass]); + this.ProcessInterlacedDefilteredScanline(this.scanline.Array, this.currentRow, pixels, Adam7FirstColumn[this.pass], Adam7ColumnIncrement[this.pass]); Swap(ref this.scanline, ref this.previousScanline); @@ -583,9 +565,10 @@ namespace ImageSharp.Formats private void ProcessDefilteredScanline(byte[] defilteredScanline, PixelAccessor pixels) where TPixel : struct, IPixel { - TPixel color = default(TPixel); - BufferSpan pixelBuffer = pixels.GetRowSpan(this.currentRow); - BufferSpan scanlineBuffer = new BufferSpan(defilteredScanline, 1); + var color = default(TPixel); + Span pixelBuffer = pixels.GetRowSpan(this.currentRow); + var scanlineBuffer = new Span(defilteredScanline, 1); + switch (this.PngColorType) { case PngColorType.Grayscale: @@ -646,7 +629,7 @@ namespace ImageSharp.Formats { byte[] newScanline = ToArrayByBitsLength(defilteredScanline, this.bytesPerScanline, this.header.BitDepth); byte[] palette = this.palette; - TPixel color = default(TPixel); + var color = default(TPixel); if (this.paletteAlpha != null && this.paletteAlpha.Length > 0) { @@ -703,7 +686,7 @@ namespace ImageSharp.Formats private void ProcessInterlacedDefilteredScanline(byte[] defilteredScanline, int row, PixelAccessor pixels, int pixelOffset = 0, int increment = 1) where TPixel : struct, IPixel { - TPixel color = default(TPixel); + var color = default(TPixel); switch (this.PngColorType) { @@ -901,7 +884,7 @@ namespace ImageSharp.Formats /// private PngChunk ReadChunk() { - PngChunk chunk = new PngChunk(); + var chunk = new PngChunk(); this.ReadChunkLength(chunk); if (chunk.Length < 0) { diff --git a/src/ImageSharp/Formats/Png/PngEncoder.cs b/src/ImageSharp/Formats/Png/PngEncoder.cs index e7b6bf30e..f89b624f7 100644 --- a/src/ImageSharp/Formats/Png/PngEncoder.cs +++ b/src/ImageSharp/Formats/Png/PngEncoder.cs @@ -33,8 +33,10 @@ namespace ImageSharp.Formats public void Encode(Image image, Stream stream, IPngEncoderOptions options) where TPixel : struct, IPixel { - PngEncoderCore encode = new PngEncoderCore(options); - encode.Encode(image, stream); + using (var 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 31e8cd90e..0482b2691 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -9,7 +9,9 @@ namespace ImageSharp.Formats using System.Buffers; using System.IO; using System.Linq; + using System.Runtime.CompilerServices; + using ImageSharp.Memory; using ImageSharp.PixelFormats; using Quantizers; @@ -19,7 +21,7 @@ namespace ImageSharp.Formats /// /// Performs the png encoding operation. /// - internal sealed class PngEncoderCore + internal sealed class PngEncoderCore : IDisposable { /// /// The maximum block size, defaults at 64k for uncompressed blocks. @@ -71,25 +73,45 @@ namespace ImageSharp.Formats /// private int bytesPerPixel; + /// + /// The number of bytes per scanline. + /// + private int bytesPerScanline; + + /// + /// The previous scanline. + /// + private Buffer previousScanline; + + /// + /// The raw scanline. + /// + private Buffer rawScanline; + + /// + /// The filtered scanline result. + /// + private Buffer result; + /// /// The buffer for the sub filter /// - private byte[] sub; + private Buffer sub; /// /// The buffer for the up filter /// - private byte[] up; + private Buffer up; /// /// The buffer for the average filter /// - private byte[] average; + private Buffer average; /// /// The buffer for the paeth filter /// - private byte[] paeth; + private Buffer paeth; /// /// The quality of output for images. @@ -177,7 +199,7 @@ namespace ImageSharp.Formats this.bytesPerPixel = this.CalculateBytesPerPixel(); - PngHeader header = new PngHeader + var header = new PngHeader { Width = image.Width, Height = image.Height, @@ -207,6 +229,20 @@ namespace ImageSharp.Formats stream.Flush(); } + /// + /// Disposes PngEncoderCore instance, disposing it's internal buffers. + /// + public void Dispose() + { + this.previousScanline?.Dispose(); + this.rawScanline?.Dispose(); + this.result?.Dispose(); + this.sub?.Dispose(); + this.up?.Dispose(); + this.average?.Dispose(); + this.paeth?.Dispose(); + } + /// /// Writes an integer to the byte array. /// @@ -268,10 +304,11 @@ namespace ImageSharp.Formats /// The pixel format. /// The image pixels accessor. /// The row index. - /// The raw scanline. - private void CollectGrayscaleBytes(PixelAccessor pixels, int row, byte[] rawScanline) + private void CollectGrayscaleBytes(PixelAccessor pixels, int row) where TPixel : struct, IPixel { + byte[] rawScanlineArray = this.rawScanline.Array; + // Copy the pixels across from the image. // Reuse the chunk type buffer. for (int x = 0; x < this.width; x++) @@ -286,11 +323,11 @@ namespace ImageSharp.Formats { if (i == 0) { - rawScanline[offset] = luminance; + rawScanlineArray[offset] = luminance; } else { - rawScanline[offset + i] = this.chunkTypeBuffer[3]; + rawScanlineArray[offset + i] = this.chunkTypeBuffer[3]; } } } @@ -302,14 +339,18 @@ namespace ImageSharp.Formats /// The pixel format. /// The image pixel accessor. /// The row index. - /// The raw scanline. - private void CollecTPixelBytes(PixelAccessor pixels, int row, byte[] rawScanline) + private void CollecTPixelBytes(PixelAccessor pixels, int row) 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)) + Span rowSpan = pixels.GetRowSpan(row); + + if (this.bytesPerPixel == 4) + { + PixelOperations.Instance.ToXyzwBytes(rowSpan, this.rawScanline, this.width); + } + else { - pixels.CopyTo(pixelRow, row); + PixelOperations.Instance.ToXyzBytes(rowSpan, this.rawScanline, this.width); } } @@ -320,81 +361,79 @@ namespace ImageSharp.Formats /// 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) + private Buffer EncodePixelRow(PixelAccessor pixels, int row) where TPixel : struct, IPixel { switch (this.pngColorType) { case PngColorType.Palette: - Buffer.BlockCopy(this.palettePixelData, row * rawScanline.Length, rawScanline, 0, rawScanline.Length); + Buffer.BlockCopy(this.palettePixelData, row * this.rawScanline.Length, this.rawScanline.Array, 0, this.rawScanline.Length); break; case PngColorType.Grayscale: case PngColorType.GrayscaleWithAlpha: - this.CollectGrayscaleBytes(pixels, row, rawScanline); + this.CollectGrayscaleBytes(pixels, row); break; default: - this.CollecTPixelBytes(pixels, row, rawScanline); + this.CollecTPixelBytes(pixels, row); break; } - return this.GetOptimalFilteredScanline(rawScanline, previousScanline, result); + return this.GetOptimalFilteredScanline(); } /// /// Applies all PNG filters to the given scanline and returns the filtered scanline that is deemed /// to be most compressible, using lowest total variation as proxy for compressibility. /// - /// The raw scanline - /// The previous scanline - /// The filtered scanline result. /// The - private byte[] GetOptimalFilteredScanline(byte[] rawScanline, byte[] previousScanline, byte[] result) + private Buffer GetOptimalFilteredScanline() { + Span scanSpan = this.rawScanline.Span; + Span prevSpan = this.previousScanline.Span; + // Palette images don't compress well with adaptive filtering. if (this.pngColorType == PngColorType.Palette || this.bitDepth < 8) { - NoneFilter.Encode(rawScanline, result); - return result; + NoneFilter.Encode(this.rawScanline, this.result); + return this.result; } // This order, while different to the enumerated order is more likely to produce a smaller sum // early on which shaves a couple of milliseconds off the processing time. - UpFilter.Encode(rawScanline, previousScanline, this.up); + UpFilter.Encode(scanSpan, prevSpan, this.up); + int currentSum = this.CalculateTotalVariation(this.up, int.MaxValue); int lowestSum = currentSum; - result = this.up; + Buffer actualResult = this.up; - PaethFilter.Encode(rawScanline, previousScanline, this.paeth, this.bytesPerPixel); + PaethFilter.Encode(scanSpan, prevSpan, this.paeth, this.bytesPerPixel); currentSum = this.CalculateTotalVariation(this.paeth, currentSum); if (currentSum < lowestSum) { lowestSum = currentSum; - result = this.paeth; + actualResult = this.paeth; } - SubFilter.Encode(rawScanline, this.sub, this.bytesPerPixel); + SubFilter.Encode(scanSpan, this.sub, this.bytesPerPixel); currentSum = this.CalculateTotalVariation(this.sub, int.MaxValue); if (currentSum < lowestSum) { lowestSum = currentSum; - result = this.sub; + actualResult = this.sub; } - AverageFilter.Encode(rawScanline, previousScanline, this.average, this.bytesPerPixel); + AverageFilter.Encode(scanSpan, prevSpan, this.average, this.bytesPerPixel); currentSum = this.CalculateTotalVariation(this.average, currentSum); if (currentSum < lowestSum) { - result = this.average; + actualResult = this.average; } - return result; + return actualResult; } /// @@ -404,17 +443,19 @@ namespace ImageSharp.Formats /// The scanline bytes /// The last variation sum /// The - private int CalculateTotalVariation(byte[] scanline, int lastSum) + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private int CalculateTotalVariation(Span scanline, int lastSum) { + ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference(); int sum = 0; - for (int i = 1; i < scanline.Length; i++) + for (int i = 1; i < this.bytesPerScanline; i++) { - byte v = scanline[i]; + byte v = Unsafe.Add(ref scanBaseRef, i); sum += v < 128 ? v : 256 - v; // No point continuing if we are larger. - if (sum > lastSum) + if (sum >= lastSum) { break; } @@ -601,18 +642,19 @@ namespace ImageSharp.Formats private void WriteDataChunks(PixelAccessor pixels, Stream stream) where TPixel : struct, IPixel { - int bytesPerScanline = this.width * this.bytesPerPixel; - byte[] previousScanline = new byte[bytesPerScanline]; - byte[] rawScanline = new byte[bytesPerScanline]; - int resultLength = bytesPerScanline + 1; - byte[] result = new byte[resultLength]; + this.bytesPerScanline = this.width * this.bytesPerPixel; + int resultLength = this.bytesPerScanline + 1; + + this.previousScanline = new Buffer(this.bytesPerScanline); + this.rawScanline = new Buffer(this.bytesPerScanline); + this.result = new Buffer(resultLength); if (this.pngColorType != PngColorType.Palette) { - this.sub = new byte[resultLength]; - this.up = new byte[resultLength]; - this.average = new byte[resultLength]; - this.paeth = new byte[resultLength]; + this.sub = Buffer.CreateClean(resultLength); + this.up = Buffer.CreateClean(resultLength); + this.average = Buffer.CreateClean(resultLength); + this.paeth = Buffer.CreateClean(resultLength); } byte[] buffer; @@ -621,13 +663,14 @@ namespace ImageSharp.Formats try { memoryStream = new MemoryStream(); - using (ZlibDeflateStream deflateStream = new ZlibDeflateStream(memoryStream, this.options.CompressionLevel)) + using (var deflateStream = new ZlibDeflateStream(memoryStream, this.options.CompressionLevel)) { for (int y = 0; y < this.height; y++) { - deflateStream.Write(this.EncodePixelRow(pixels, y, previousScanline, rawScanline, result), 0, resultLength); + Buffer r = this.EncodePixelRow(pixels, y); + deflateStream.Write(r.Array, 0, resultLength); - Swap(ref rawScanline, ref previousScanline); + Swap(ref this.rawScanline, ref this.previousScanline); } } diff --git a/src/ImageSharp/Image.Create.cs b/src/ImageSharp/Image.Create.cs deleted file mode 100644 index 3d92cd66b..000000000 --- a/src/ImageSharp/Image.Create.cs +++ /dev/null @@ -1,62 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp -{ - 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. - /// - public sealed partial class Image - { - /// - /// Create a new instance of the class - /// with the height and the width of the image. - /// - /// The pixel format. - /// The width of the image in pixels. - /// The height of the image in pixels. - /// The images matadata to preload. - /// - /// The configuration providing initialization code which allows extending the library. - /// - /// - /// A new unless is in which case it returns - /// - internal static Image Create(int width, int height, ImageMetaData metadata, Configuration configuration) - where TPixel : struct, IPixel - { - if (typeof(TPixel) == typeof(Rgba32)) - { - return new Image(width, height, metadata, configuration) as Image; - } - else - { - return new Image(width, height, metadata, configuration); - } - } - - /// - /// Create a new instance of the class - /// with the height and the width of the image. - /// - /// 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 - /// - internal static Image Create(int width, int height, Configuration configuration) - where TPixel : struct, IPixel - { - return Image.Create(width, height, null, configuration); - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/Image.cs b/src/ImageSharp/Image.cs deleted file mode 100644 index 3d33e6263..000000000 --- a/src/ImageSharp/Image.cs +++ /dev/null @@ -1,69 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp -{ - using System.Diagnostics; - 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 - { - /// - /// Initializes a new instance of the class - /// with the height and the width of the image. - /// - /// The width of the image in pixels. - /// The height of the image in pixels. - /// - /// The configuration providing initialization code which allows extending the library. - /// - public Image(int width, int height, Configuration configuration) - : base(width, height, configuration) - { - } - - /// - /// Initializes a new instance of the class - /// with the height and the width of the image. - /// - /// The width of the image in pixels. - /// The height of the image in pixels. - public Image(int width, int height) - : this(width, height, null) - { - } - - /// - /// 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) - : base(other) - { - } - - /// - /// Initializes a new instance of the class - /// with the height and the width of the image. - /// - /// The width of the image in pixels. - /// The height of the image in pixels. - /// The metadata. - /// - /// The configuration providing initialization code which allows extending the library. - /// - internal Image(int width, int height, ImageMetaData metadata, Configuration configuration) - : base(width, height, metadata, configuration) - { - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/Image.Decode.cs b/src/ImageSharp/Image/Image.Decode.cs similarity index 88% rename from src/ImageSharp/Image.Decode.cs rename to src/ImageSharp/Image/Image.Decode.cs index b0e476280..c162f1772 100644 --- a/src/ImageSharp/Image.Decode.cs +++ b/src/ImageSharp/Image/Image.Decode.cs @@ -12,11 +12,10 @@ namespace ImageSharp 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. - /// - public sealed partial class Image + /// + /// Adds static methods allowing the decoding of new images. + /// + public static partial class Image { /// /// By reading the header on the provided stream this calculates the images format. @@ -53,15 +52,15 @@ namespace ImageSharp /// /// Decodes the image stream to the current image. /// - /// The pixel format. /// The stream. /// The options for the decoder. /// the configuration. + /// The pixel format. /// - /// The decoded image + /// A new . /// private static Image Decode(Stream stream, IDecoderOptions options, Configuration config) - where TPixel : struct, IPixel + where TPixel : struct, IPixel { IImageFormat format = DiscoverFormat(stream, config); if (format == null) @@ -74,4 +73,4 @@ namespace ImageSharp return img; } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Image.FromBytes.cs b/src/ImageSharp/Image/Image.FromBytes.cs similarity index 51% rename from src/ImageSharp/Image.FromBytes.cs rename to src/ImageSharp/Image/Image.FromBytes.cs index 540eb6016..c7309c4b1 100644 --- a/src/ImageSharp/Image.FromBytes.cs +++ b/src/ImageSharp/Image/Image.FromBytes.cs @@ -1,122 +1,75 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // 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 - /// packed into a single unsigned integer value. - /// - public sealed partial class Image + /// + /// Adds static methods allowing the creation of new image from a byte array. + /// + public static partial class Image { /// - /// Loads the image from the given byte array. + /// Create a new instance of the class from the given byte array. /// /// The byte array containing image data. - /// - /// Thrown if the stream is not readable nor seekable. - /// - /// The image - public static Image Load(byte[] data) - { - return Load(null, data, null); - } + /// A new . + public static Image Load(byte[] data) => Load(null, data, null); /// - /// Loads the image from the given byte array. + /// Create a new instance of the class from the given byte array. /// /// 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) - { - return Load(null, data, options); - } + /// A new . + public static Image Load(byte[] data, IDecoderOptions options) => Load(null, data, options); /// - /// Loads the image from the given byte array. + /// Create a new instance of the class from the given byte array. /// /// 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) - { - return Load(config, data, null); - } + /// A new . + public static Image Load(Configuration config, byte[] data) => Load(config, data, null); /// - /// Loads the image from the given byte array. + /// Create a new instance of the class from the given byte array. /// /// 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) - { - return Load(data, decoder, null); - } + /// A new . + public static Image Load(byte[] data, IImageDecoder decoder) => Load(data, decoder, null); /// - /// Loads the image from the given byte array. + /// Create a new instance of the class from the given byte array. /// /// The configuration options. /// 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(Configuration config, byte[] data, IDecoderOptions options) - { - using (MemoryStream ms = new MemoryStream(data)) - { - return Load(config, ms, options); - } - } + /// A new . + public static Image Load(Configuration config, byte[] data, IDecoderOptions options) => Load(config, data, options); /// - /// Loads the image from the given byte array. + /// Create a new instance of the class from the given byte array. /// /// The byte array containing image data. /// The decoder. /// The options for the decoder. - /// - /// Thrown if the stream is not readable nor seekable. - /// - /// The image - public static Image Load(byte[] data, IImageDecoder decoder, IDecoderOptions options) - { - using (MemoryStream ms = new MemoryStream(data)) - { - return Load(ms, decoder, options); - } - } + /// A new . + public static Image Load(byte[] data, IImageDecoder decoder, IDecoderOptions options) => Load(data, decoder, options); /// - /// Loads the image from the given byte array. + /// Create a new instance of the class from the given byte array. /// - /// The pixel format. /// The byte array containing image data. - /// - /// Thrown if the stream is not readable nor seekable. - /// - /// The image + /// The pixel format. + /// A new . public static Image Load(byte[] data) where TPixel : struct, IPixel { @@ -124,15 +77,12 @@ namespace ImageSharp } /// - /// Loads the image from the given byte array. + /// Create a new instance of the class from the given byte array. /// - /// 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 + /// The pixel format. + /// A new . public static Image Load(byte[] data, IDecoderOptions options) where TPixel : struct, IPixel { @@ -140,15 +90,12 @@ namespace ImageSharp } /// - /// Loads the image from the given byte array. + /// Create a new instance of the class from the given byte array. /// - /// 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 + /// The pixel format. + /// A new . public static Image Load(Configuration config, byte[] data) where TPixel : struct, IPixel { @@ -156,15 +103,12 @@ namespace ImageSharp } /// - /// Loads the image from the given byte array. + /// Create a new instance of the class from the given byte array. /// - /// The pixel format. /// The byte array containing image data. /// The decoder. - /// - /// Thrown if the stream is not readable nor seekable. - /// - /// The image + /// The pixel format. + /// A new . public static Image Load(byte[] data, IImageDecoder decoder) where TPixel : struct, IPixel { @@ -172,16 +116,13 @@ namespace ImageSharp } /// - /// Loads the image from the given byte array. + /// Create a new instance of the class from the given byte array. /// - /// The pixel format. /// The configuration options. /// The byte array containing image data. /// The options for the decoder. - /// - /// Thrown if the stream is not readable nor seekable. - /// - /// The image + /// The pixel format. + /// A new . public static Image Load(Configuration config, byte[] data, IDecoderOptions options) where TPixel : struct, IPixel { @@ -192,16 +133,13 @@ namespace ImageSharp } /// - /// Loads the image from the given byte array. + /// Create a new instance of the class from the given byte array. /// - /// The pixel format. /// The byte array containing image data. /// The decoder. /// The options for the decoder. - /// - /// Thrown if the stream is not readable nor seekable. - /// - /// The image + /// The pixel format. + /// A new . public static Image Load(byte[] data, IImageDecoder decoder, IDecoderOptions options) where TPixel : struct, IPixel { @@ -211,4 +149,4 @@ namespace ImageSharp } } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Image.FromFile.cs b/src/ImageSharp/Image/Image.FromFile.cs similarity index 69% rename from src/ImageSharp/Image.FromFile.cs rename to src/ImageSharp/Image/Image.FromFile.cs index 8f4c9138b..a135c43f5 100644 --- a/src/ImageSharp/Image.FromFile.cs +++ b/src/ImageSharp/Image/Image.FromFile.cs @@ -11,110 +11,87 @@ namespace ImageSharp 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. - /// - public sealed partial class Image + /// + /// Adds static methods allowing the creation of new image from a given file. + /// + public static partial class Image { /// - /// Loads the image from the given file. + /// Create a new instance of the class from the given file. /// /// The file path to the image. /// /// Thrown if the stream is not readable nor seekable. /// - /// The image - public static Image Load(string path) - { - return Load(null, path, null); - } + /// A new . + public static Image Load(string path) => Load(path); /// - /// Loads the image from the given file. + /// Create a new instance of the class from the given file. /// /// 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) - { - return Load(null, path, options); - } + /// A new . + public static Image Load(string path, IDecoderOptions options) => Load(path, options); /// - /// Loads the image from the given file. + /// Create a new instance of the class from the given file. /// /// 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) - { - return Load(config, path, null); - } + /// A new . + public static Image Load(Configuration config, string path) => Load(config, path); /// - /// Loads the image from the given file. + /// Create a new instance of the class from the given file. /// /// 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) - { - return Load(path, decoder, null); - } + /// A new . + public static Image Load(string path, IImageDecoder decoder) => Load(path, decoder); /// - /// Loads the image from the given file. + /// Create a new instance of the class from the given file. /// + /// The configuration options. /// The file path to the image. - /// The decoder. /// The options for the decoder. /// /// Thrown if the stream is not readable nor seekable. /// - /// The image - public static Image Load(string path, IImageDecoder decoder, IDecoderOptions options) - { - return new Image(Load(path, decoder, options)); - } + /// A new . + public static Image Load(Configuration config, string path, IDecoderOptions options) => Load(config, path, options); /// - /// Loads the image from the given file. + /// Create a new instance of the class from the given file. /// - /// The configuration options. /// The file path to the image. + /// The decoder. /// The options for the decoder. /// /// Thrown if the stream is not readable nor seekable. /// - /// The image - public static Image Load(Configuration config, string path, IDecoderOptions options) - { - config = config ?? Configuration.Default; - using (Stream s = config.FileSystem.OpenRead(path)) - { - return Load(config, s, options); - } - } + /// A new . + public static Image Load(string path, IImageDecoder decoder, IDecoderOptions options) => Load(path, decoder, options); /// - /// Loads the image from the given file. + /// Create a new instance of the class from the given file. /// - /// The pixel format. /// The file path to the image. /// /// Thrown if the stream is not readable nor seekable. /// - /// The image + /// The pixel format. + /// A new . public static Image Load(string path) where TPixel : struct, IPixel { @@ -122,15 +99,15 @@ namespace ImageSharp } /// - /// Loads the image from the given file. + /// Create a new instance of the class from the given file. /// - /// 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 + /// The pixel format. + /// A new . public static Image Load(string path, IDecoderOptions options) where TPixel : struct, IPixel { @@ -138,15 +115,15 @@ namespace ImageSharp } /// - /// Loads the image from the given file. + /// Create a new instance of the class from the given file. /// - /// 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 + /// The pixel format. + /// A new . public static Image Load(Configuration config, string path) where TPixel : struct, IPixel { @@ -154,15 +131,15 @@ namespace ImageSharp } /// - /// Loads the image from the given file. + /// Create a new instance of the class from the given file. /// - /// The pixel format. /// The file path to the image. /// The decoder. /// /// Thrown if the stream is not readable nor seekable. /// - /// The image + /// The pixel format. + /// A new . public static Image Load(string path, IImageDecoder decoder) where TPixel : struct, IPixel { @@ -170,16 +147,16 @@ namespace ImageSharp } /// - /// Loads the image from the given file. + /// Create a new instance of the class from the given file. /// - /// The pixel format. /// The configuration options. /// The file path to the image. /// The options for the decoder. /// /// Thrown if the stream is not readable nor seekable. /// - /// The image + /// The pixel format. + /// A new . public static Image Load(Configuration config, string path, IDecoderOptions options) where TPixel : struct, IPixel { @@ -191,16 +168,16 @@ namespace ImageSharp } /// - /// Loads the image from the given file. + /// Create a new instance of the class from the given file. /// - /// The pixel format. /// The file path to the image. /// The decoder. /// The options for the decoder. /// /// Thrown if the stream is not readable nor seekable. /// - /// The image + /// The pixel format. + /// A new . public static Image Load(string path, IImageDecoder decoder, IDecoderOptions options) where TPixel : struct, IPixel { @@ -212,4 +189,4 @@ namespace ImageSharp } } #endif -} +} \ No newline at end of file diff --git a/src/ImageSharp/Image.FromStream.cs b/src/ImageSharp/Image/Image.FromStream.cs similarity index 68% rename from src/ImageSharp/Image.FromStream.cs rename to src/ImageSharp/Image/Image.FromStream.cs index a34c6b7b3..1bcb5adc9 100644 --- a/src/ImageSharp/Image.FromStream.cs +++ b/src/ImageSharp/Image/Image.FromStream.cs @@ -7,92 +7,61 @@ 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. - /// - public sealed partial class Image + /// + /// Adds static methods allowing the creation of new image from a given stream. + /// + public static partial class Image { /// - /// Loads the image from the given stream. + /// Create a new instance of the class from the given stream. /// /// The stream containing image information. /// /// Thrown if the stream is not readable nor seekable. /// - /// The image - public static Image Load(Stream stream) - { - return Load(null, stream, null); - } + /// A new .> + public static Image Load(Stream stream) => Load(stream); /// - /// Loads the image from the given stream. + /// Create a new instance of the class from the given stream. /// /// 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) - { - return Load(null, stream, options); - } - - /// - /// Loads the image from the given stream. - /// - /// 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) - { - return Load(config, stream, null); - } + /// A new .> + public static Image Load(Stream stream, IDecoderOptions options) => Load(stream, options); /// - /// Loads the image from the given stream. + /// Create a new instance of the class from the given stream. /// /// 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) - { - return Load(stream, decoder, null); - } + /// A new .> + public static Image Load(Stream stream, IImageDecoder decoder) => Load(stream, decoder); /// - /// Loads the image from the given stream. + /// Create a new instance of the class from the given stream. /// - /// The configuration options. + /// The config for the decoder. /// 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(Configuration config, Stream stream, IDecoderOptions options) - { - Image image = Load(config, stream, options); - - return image as Image ?? new Image(image); - } + /// A new .> + public static Image Load(Configuration config, Stream stream) => Load(config, stream); /// - /// Loads the image from the given stream. + /// Create a new instance of the class from the given stream. /// /// The stream containing image information. /// The decoder. @@ -100,23 +69,18 @@ namespace ImageSharp /// /// Thrown if the stream is not readable nor seekable. /// - /// The image - public static Image Load(Stream stream, IImageDecoder decoder, IDecoderOptions options) - { - Image image = new Image(Load(stream, decoder, options)); - - return image as Image ?? new Image(image); - } + /// A new .> + public static Image Load(Stream stream, IImageDecoder decoder, IDecoderOptions options) => Load(stream, decoder, options); /// - /// Loads the image from the given stream. + /// Create a new instance of the class from the given stream. /// - /// The pixel format. /// The stream containing image information. /// /// Thrown if the stream is not readable nor seekable. /// - /// The image + /// The pixel format. + /// A new .> public static Image Load(Stream stream) where TPixel : struct, IPixel { @@ -124,15 +88,15 @@ namespace ImageSharp } /// - /// Loads the image from the given stream. + /// Create a new instance of the class from the given stream. /// - /// The pixel format. /// The stream containing image information. /// The options for the decoder. /// /// Thrown if the stream is not readable nor seekable. /// - /// The image + /// The pixel format. + /// A new .> public static Image Load(Stream stream, IDecoderOptions options) where TPixel : struct, IPixel { @@ -140,15 +104,15 @@ namespace ImageSharp } /// - /// Loads the image from the given stream. + /// Create a new instance of the class from the given stream. /// - /// The pixel format. /// The config for the decoder. /// The stream containing image information. /// /// Thrown if the stream is not readable nor seekable. /// - /// The image + /// The pixel format. + /// A new .> public static Image Load(Configuration config, Stream stream) where TPixel : struct, IPixel { @@ -156,15 +120,15 @@ namespace ImageSharp } /// - /// Loads the image from the given stream. + /// Create a new instance of the class from the given stream. /// - /// The pixel format. /// The stream containing image information. /// The decoder. /// /// Thrown if the stream is not readable nor seekable. /// - /// The image + /// The pixel format. + /// A new .> public static Image Load(Stream stream, IImageDecoder decoder) where TPixel : struct, IPixel { @@ -172,16 +136,16 @@ namespace ImageSharp } /// - /// Loads the image from the given stream. + /// Create a new instance of the class from the given stream. /// - /// The pixel format. /// The stream containing image information. /// The decoder. /// The options for the decoder. /// /// Thrown if the stream is not readable nor seekable. /// - /// The image + /// The pixel format. + /// A new .> public static Image Load(Stream stream, IImageDecoder decoder, IDecoderOptions options) where TPixel : struct, IPixel { @@ -189,21 +153,20 @@ namespace ImageSharp } /// - /// Loads the image from the given stream. + /// Create a new instance of the class from the given stream. /// - /// The pixel format. /// The configuration options. /// The stream containing image information. /// The options for the decoder. /// /// Thrown if the stream is not readable nor seekable. /// - /// The image + /// The pixel format. + /// A new .> 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)); if (img != null) @@ -233,17 +196,15 @@ namespace ImageSharp { return action(stream); } - else + + // We want to be able to load images from things like HttpContext.Request.Body + using (MemoryStream ms = new MemoryStream()) { - // We want to be able to load images from things like HttpContext.Request.Body - using (MemoryStream ms = new MemoryStream()) - { - stream.CopyTo(ms); - ms.Position = 0; - - return action(ms); - } + stream.CopyTo(ms); + ms.Position = 0; + + return action(ms); } } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Image/ImageBase{TPixel}.cs b/src/ImageSharp/Image/ImageBase{TPixel}.cs index 7bad03cc8..4fd9d26cb 100644 --- a/src/ImageSharp/Image/ImageBase{TPixel}.cs +++ b/src/ImageSharp/Image/ImageBase{TPixel}.cs @@ -7,6 +7,8 @@ namespace ImageSharp { using System; using System.Diagnostics; + + using ImageSharp.Memory; using ImageSharp.PixelFormats; using Processing; @@ -59,15 +61,15 @@ namespace ImageSharp /// /// Initializes a new instance of the class. /// - /// The width of the image in pixels. - /// The height of the image in pixels. /// /// The configuration providing initialization code which allows extending the library. /// + /// The width of the image in pixels. + /// The height of the image in pixels. /// /// Thrown if either or are less than or equal to 0. /// - protected ImageBase(int width, int height, Configuration configuration) + protected ImageBase(Configuration configuration, int width, int height) : this(configuration) { Guard.MustBeGreaterThan(width, 0, nameof(width)); diff --git a/src/ImageSharp/Image/ImageFrame{TPixel}.cs b/src/ImageSharp/Image/ImageFrame{TPixel}.cs index 0731b1443..04b9902c6 100644 --- a/src/ImageSharp/Image/ImageFrame{TPixel}.cs +++ b/src/ImageSharp/Image/ImageFrame{TPixel}.cs @@ -26,7 +26,7 @@ namespace ImageSharp /// The configuration providing initialization code which allows extending the library. /// public ImageFrame(int width, int height, Configuration configuration = null) - : base(width, height, configuration) + : base(configuration, width, height) { } diff --git a/src/ImageSharp/Image/Image{TPixel}.cs b/src/ImageSharp/Image/Image{TPixel}.cs index 9e103c700..092706e41 100644 --- a/src/ImageSharp/Image/Image{TPixel}.cs +++ b/src/ImageSharp/Image/Image{TPixel}.cs @@ -29,13 +29,13 @@ namespace ImageSharp /// Initializes a new instance of the class /// with the height and the width of the image. /// - /// The width of the image in pixels. - /// The height of the image in pixels. /// /// The configuration providing initialization code which allows extending the library. /// - public Image(int width, int height, Configuration configuration) - : this(width, height, new ImageMetaData(), configuration) + /// The width of the image in pixels. + /// The height of the image in pixels. + public Image(Configuration configuration, int width, int height) + : this(configuration, width, height, new ImageMetaData()) { } @@ -46,7 +46,7 @@ namespace ImageSharp /// The width of the image in pixels. /// The height of the image in pixels. public Image(int width, int height) - : this(width, height, null) + : this(null, width, height) { } @@ -85,14 +85,14 @@ namespace ImageSharp /// Initializes a new instance of the class /// with the height and the width of the image. /// - /// The width of the image in pixels. - /// The height of the image in pixels. - /// The images metadata. /// /// The configuration providing initialization code which allows extending the library. /// - internal Image(int width, int height, ImageMetaData metadata, Configuration configuration) - : base(width, height, configuration) + /// The width of the image in pixels. + /// The height of the image in pixels. + /// The images metadata. + internal Image(Configuration configuration, int width, int height, ImageMetaData metadata) + : base(configuration, width, height) { if (!this.Configuration.ImageFormats.Any()) { @@ -359,7 +359,7 @@ namespace ImageSharp { scaleFunc = PackedPixelConverterHelper.ComputeScaleFunction(scaleFunc); - Image target = new Image(this.Width, this.Height, this.Configuration); + Image target = new Image(this.Configuration, this.Width, this.Height); target.CopyProperties(this); using (PixelAccessor pixels = this.Lock()) diff --git a/src/ImageSharp/Image/PixelAccessor{TPixel}.cs b/src/ImageSharp/Image/PixelAccessor{TPixel}.cs index 1e46a672e..a54c03b63 100644 --- a/src/ImageSharp/Image/PixelAccessor{TPixel}.cs +++ b/src/ImageSharp/Image/PixelAccessor{TPixel}.cs @@ -9,6 +9,8 @@ namespace ImageSharp using System.Diagnostics; using System.Runtime.CompilerServices; using System.Threading.Tasks; + + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// @@ -114,7 +116,7 @@ namespace ImageSharp public ParallelOptions ParallelOptions { get; } /// - BufferSpan IBuffer2D.Span => this.pixelBuffer; + Span IBuffer2D.Span => this.pixelBuffer; private static PixelOperations Operations => PixelOperations.Instance; @@ -250,7 +252,7 @@ namespace ImageSharp /// The target pixel buffer accessor. internal void CopyTo(PixelAccessor target) { - BufferSpan.Copy(this.pixelBuffer.Span, target.pixelBuffer.Span); + SpanHelper.Copy(this.pixelBuffer.Span, target.pixelBuffer.Span); } /// @@ -266,8 +268,8 @@ namespace ImageSharp { for (int y = 0; y < height; y++) { - BufferSpan source = area.GetRowSpan(y); - BufferSpan destination = this.GetRowSpan(targetX, targetY + y); + Span source = area.GetRowSpan(y); + Span destination = this.GetRowSpan(targetX, targetY + y); Operations.PackFromZyxBytes(source, destination, width); } @@ -286,8 +288,8 @@ namespace ImageSharp { for (int y = 0; y < height; y++) { - BufferSpan source = area.GetRowSpan(y); - BufferSpan destination = this.GetRowSpan(targetX, targetY + y); + Span source = area.GetRowSpan(y); + Span destination = this.GetRowSpan(targetX, targetY + y); Operations.PackFromZyxwBytes(source, destination, width); } @@ -306,8 +308,8 @@ namespace ImageSharp { for (int y = 0; y < height; y++) { - BufferSpan source = area.GetRowSpan(y); - BufferSpan destination = this.GetRowSpan(targetX, targetY + y); + Span source = area.GetRowSpan(y); + Span destination = this.GetRowSpan(targetX, targetY + y); Operations.PackFromXyzBytes(source, destination, width); } @@ -326,8 +328,8 @@ namespace ImageSharp { for (int y = 0; y < height; y++) { - BufferSpan source = area.GetRowSpan(y); - BufferSpan destination = this.GetRowSpan(targetX, targetY + y); + Span source = area.GetRowSpan(y); + Span destination = this.GetRowSpan(targetX, targetY + y); Operations.PackFromXyzwBytes(source, destination, width); } } @@ -345,8 +347,8 @@ namespace ImageSharp { for (int y = 0; y < height; y++) { - BufferSpan source = this.GetRowSpan(sourceX, sourceY + y); - BufferSpan destination = area.GetRowSpan(y); + Span source = this.GetRowSpan(sourceX, sourceY + y); + Span destination = area.GetRowSpan(y); Operations.ToZyxBytes(source, destination, width); } } @@ -364,8 +366,8 @@ namespace ImageSharp { for (int y = 0; y < height; y++) { - BufferSpan source = this.GetRowSpan(sourceX, sourceY + y); - BufferSpan destination = area.GetRowSpan(y); + Span source = this.GetRowSpan(sourceX, sourceY + y); + Span destination = area.GetRowSpan(y); Operations.ToZyxwBytes(source, destination, width); } } @@ -383,8 +385,8 @@ namespace ImageSharp { for (int y = 0; y < height; y++) { - BufferSpan source = this.GetRowSpan(sourceX, sourceY + y); - BufferSpan destination = area.GetRowSpan(y); + Span source = this.GetRowSpan(sourceX, sourceY + y); + Span destination = area.GetRowSpan(y); Operations.ToXyzBytes(source, destination, width); } } @@ -402,8 +404,8 @@ namespace ImageSharp { for (int y = 0; y < height; y++) { - BufferSpan source = this.GetRowSpan(sourceX, sourceY + y); - BufferSpan destination = area.GetRowSpan(y); + Span source = this.GetRowSpan(sourceX, sourceY + y); + Span destination = area.GetRowSpan(y); Operations.ToXyzwBytes(source, destination, width); } } diff --git a/src/ImageSharp/Image/PixelArea{TPixel}.cs b/src/ImageSharp/Image/PixelArea{TPixel}.cs index 3dd187768..4ddfcadb7 100644 --- a/src/ImageSharp/Image/PixelArea{TPixel}.cs +++ b/src/ImageSharp/Image/PixelArea{TPixel}.cs @@ -8,6 +8,8 @@ namespace ImageSharp using System; using System.Diagnostics; using System.IO; + + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// @@ -191,11 +193,11 @@ namespace ImageSharp } /// - /// Gets a to the row y. + /// Gets a to the row y. /// /// The y coordinate - /// The - internal BufferSpan GetRowSpan(int y) + /// The + internal Span GetRowSpan(int y) { return this.byteBuffer.Slice(y * this.RowStride); } diff --git a/src/ImageSharp/ImageSharp.csproj b/src/ImageSharp/ImageSharp.csproj index 16fff3212..6194be1bf 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-alpha8 + 1.0.0-alpha9 James Jackson-South and contributors netstandard1.3;netstandard1.1 true @@ -38,8 +38,9 @@ All + - + diff --git a/src/ImageSharp/Common/Memory/Buffer.cs b/src/ImageSharp/Memory/Buffer.cs similarity index 88% rename from src/ImageSharp/Common/Memory/Buffer.cs rename to src/ImageSharp/Memory/Buffer.cs index c26b8ea18..a894ea53a 100644 --- a/src/ImageSharp/Common/Memory/Buffer.cs +++ b/src/ImageSharp/Memory/Buffer.cs @@ -3,10 +3,9 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.Memory { using System; - using System.Buffers; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -97,9 +96,9 @@ namespace ImageSharp public T[] Array { get; private set; } /// - /// Gets a to the backing buffer. + /// Gets a to the backing buffer. /// - public BufferSpan Span => this; + public Span Span => this; /// /// Returns a reference to specified element of the buffer. @@ -117,13 +116,13 @@ namespace ImageSharp } /// - /// Converts to an . + /// Converts to an . /// /// The to convert. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static implicit operator BufferSpan(Buffer buffer) + public static implicit operator Span(Buffer buffer) { - return new BufferSpan(buffer.Array, 0, buffer.Length); + return new Span(buffer.Array, 0, buffer.Length); } /// @@ -140,26 +139,26 @@ namespace ImageSharp } /// - /// Gets a to an offseted position inside the buffer. + /// Gets a to an offseted position inside the buffer. /// /// The start - /// The + /// The [MethodImpl(MethodImplOptions.AggressiveInlining)] - public BufferSpan Slice(int start) + public Span Slice(int start) { - return new BufferSpan(this.Array, start, this.Length - start); + return new Span(this.Array, start, this.Length - start); } /// - /// Gets a to an offseted position inside the buffer. + /// Gets a to an offsetted position inside the buffer. /// /// The start /// The length of the slice - /// The + /// The [MethodImpl(MethodImplOptions.AggressiveInlining)] - public BufferSpan Slice(int start, int length) + public Span Slice(int start, int length) { - return new BufferSpan(this.Array, start, length); + return new Span(this.Array, start, length); } /// @@ -210,7 +209,7 @@ namespace ImageSharp } /// - /// Clears the buffer, filling elements between 0 and -1 with default(T) + /// Clears the contents of this buffer. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Clear() diff --git a/src/ImageSharp/Common/Memory/Buffer2D.cs b/src/ImageSharp/Memory/Buffer2D.cs similarity index 98% rename from src/ImageSharp/Common/Memory/Buffer2D.cs rename to src/ImageSharp/Memory/Buffer2D.cs index c4eb50700..e5ccfbd19 100644 --- a/src/ImageSharp/Common/Memory/Buffer2D.cs +++ b/src/ImageSharp/Memory/Buffer2D.cs @@ -3,9 +3,8 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.Memory { - using System; using System.Runtime.CompilerServices; /// diff --git a/src/ImageSharp/Common/Memory/Buffer2DExtensions.cs b/src/ImageSharp/Memory/Buffer2DExtensions.cs similarity index 71% rename from src/ImageSharp/Common/Memory/Buffer2DExtensions.cs rename to src/ImageSharp/Memory/Buffer2DExtensions.cs index 4c3cc4d40..51e558281 100644 --- a/src/ImageSharp/Common/Memory/Buffer2DExtensions.cs +++ b/src/ImageSharp/Memory/Buffer2DExtensions.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.Memory { using System; using System.Runtime.CompilerServices; @@ -14,29 +14,29 @@ namespace ImageSharp internal static class Buffer2DExtensions { /// - /// Gets a to the row 'y' beginning from the pixel at 'x'. + /// Gets a to the row 'y' beginning from the pixel at 'x'. /// /// The buffer /// The x coordinate (position in the row) /// The y (row) coordinate /// The element type - /// The + /// The [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static BufferSpan GetRowSpan(this IBuffer2D buffer, int x, int y) + public static Span GetRowSpan(this IBuffer2D buffer, int x, int y) where T : struct { return buffer.Span.Slice((y * buffer.Width) + x, buffer.Width - x); } /// - /// Gets a to the row 'y' beginning from the pixel at 'x'. + /// Gets a to the row 'y' beginning from the pixel at 'x'. /// /// The buffer /// The y (row) coordinate /// The element type - /// The + /// The [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static BufferSpan GetRowSpan(this IBuffer2D buffer, int y) + public static Span GetRowSpan(this IBuffer2D buffer, int y) where T : struct { return buffer.Span.Slice(y * buffer.Width, buffer.Width); diff --git a/src/ImageSharp/Common/Memory/Fast2DArray{T}.cs b/src/ImageSharp/Memory/Fast2DArray{T}.cs similarity index 96% rename from src/ImageSharp/Common/Memory/Fast2DArray{T}.cs rename to src/ImageSharp/Memory/Fast2DArray{T}.cs index 401c83ce6..260c829e2 100644 --- a/src/ImageSharp/Common/Memory/Fast2DArray{T}.cs +++ b/src/ImageSharp/Memory/Fast2DArray{T}.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.Memory { using System; using System.Diagnostics; @@ -94,11 +94,11 @@ namespace ImageSharp } /// - /// Performs an implicit conversion from a 2D array to a . + /// Performs an implicit conversion from a 2D array to a . /// /// The source array. /// - /// The represenation on the source data. + /// The represenation on the source data. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator Fast2DArray(T[,] data) diff --git a/src/ImageSharp/Common/Memory/IBuffer2D.cs b/src/ImageSharp/Memory/IBuffer2D.cs similarity index 84% rename from src/ImageSharp/Common/Memory/IBuffer2D.cs rename to src/ImageSharp/Memory/IBuffer2D.cs index 1ba08e49f..300c29a1b 100644 --- a/src/ImageSharp/Common/Memory/IBuffer2D.cs +++ b/src/ImageSharp/Memory/IBuffer2D.cs @@ -3,8 +3,10 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.Memory { + using System; + /// /// An interface that represents a pinned buffer of value type objects /// interpreted as a 2D region of x elements. @@ -24,8 +26,8 @@ namespace ImageSharp int Height { get; } /// - /// Gets a to the backing buffer. + /// Gets a to the backing buffer. /// - BufferSpan Span { get; } + Span Span { get; } } } \ No newline at end of file diff --git a/src/ImageSharp/Common/Memory/PixelDataPool{T}.cs b/src/ImageSharp/Memory/PixelDataPool{T}.cs similarity index 98% rename from src/ImageSharp/Common/Memory/PixelDataPool{T}.cs rename to src/ImageSharp/Memory/PixelDataPool{T}.cs index 0ec367d24..a8b5501cc 100644 --- a/src/ImageSharp/Common/Memory/PixelDataPool{T}.cs +++ b/src/ImageSharp/Memory/PixelDataPool{T}.cs @@ -3,9 +3,8 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.Memory { - using System; using System.Buffers; using ImageSharp.PixelFormats; diff --git a/src/ImageSharp/Common/Memory/BufferSpan.cs b/src/ImageSharp/Memory/SpanHelper.cs similarity index 68% rename from src/ImageSharp/Common/Memory/BufferSpan.cs rename to src/ImageSharp/Memory/SpanHelper.cs index c51c110be..57b771591 100644 --- a/src/ImageSharp/Common/Memory/BufferSpan.cs +++ b/src/ImageSharp/Memory/SpanHelper.cs @@ -1,28 +1,41 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.Memory { using System; + using System.Numerics; using System.Runtime.CompilerServices; - using System.Runtime.InteropServices; /// - /// Utility methods for + /// Utility methods for /// - internal static class BufferSpan + internal static class SpanHelper { + /// + /// Fetches a from the beginning of the span. + /// + /// The value type + /// The span to fetch the vector from + /// A reference to the beginning of the span + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ref Vector FetchVector(this Span span) + where T : struct + { + return ref Unsafe.As>(ref span.DangerousGetPinnableReference()); + } + /// /// Copy 'count' number of elements of the same type from 'source' to 'dest' /// /// The element type. - /// The to copy elements from. - /// The destination . + /// The to copy elements from. + /// The destination . /// The number of elements to copy [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static unsafe void Copy(BufferSpan source, BufferSpan destination, int count) + public static unsafe void Copy(Span source, Span destination, int count) where T : struct { DebugGuard.MustBeLessThanOrEqualTo(count, source.Length, nameof(count)); @@ -34,6 +47,7 @@ namespace ImageSharp int byteCount = Unsafe.SizeOf() * count; // TODO: Use unfixed Unsafe.CopyBlock(ref T, ref T, int) for small blocks, when it gets available! + // This is now available. Check with Anton re intent. Do we replace both ifdefs? fixed (byte* pSrc = &srcRef) fixed (byte* pDest = &destRef) { @@ -50,10 +64,10 @@ namespace ImageSharp /// Copy all elements of 'source' into 'destination'. /// /// The element type. - /// The to copy elements from. - /// The destination . + /// The to copy elements from. + /// The destination . [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Copy(BufferSpan source, BufferSpan destination) + public static void Copy(Span source, Span destination) where T : struct { Copy(source, destination, source.Length); diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs index f65c02043..a7fd8fd6a 100644 --- a/src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs +++ b/src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs @@ -5,7 +5,6 @@ namespace ImageSharp { - using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; @@ -137,7 +136,7 @@ namespace ImageSharp return null; } - using (MemoryStream memStream = new MemoryStream(this.data, this.thumbnailOffset, this.thumbnailLength)) + using (var memStream = new MemoryStream(this.data, this.thumbnailOffset, this.thumbnailLength)) { return Image.Load(memStream); } @@ -202,7 +201,7 @@ namespace ImageSharp } } - ExifValue newExifValue = ExifValue.Create(tag, value); + var newExifValue = ExifValue.Create(tag, value); this.values.Add(newExifValue); } @@ -222,7 +221,7 @@ namespace ImageSharp return null; } - ExifWriter writer = new ExifWriter(this.values, this.Parts); + var writer = new ExifWriter(this.values, this.Parts); return writer.GetData(); } @@ -239,11 +238,18 @@ namespace ImageSharp private void SyncResolution(ExifTag tag, double resolution) { ExifValue value = this.GetValue(tag); - if (value != null) + if (value == null) { - Rational newResolution = new Rational(resolution, false); - this.SetValue(tag, newResolution); + return; } + + if (value.IsArray || value.DataType != ExifDataType.Rational) + { + this.RemoveValue(value.Tag); + } + + var newResolution = new Rational(resolution, false); + this.SetValue(tag, newResolution); } private void InitializeValues() @@ -259,7 +265,7 @@ namespace ImageSharp return; } - ExifReader reader = new ExifReader(); + var reader = new ExifReader(); this.values = reader.Read(this.data); this.invalidTags = new List(reader.InvalidTags); this.thumbnailOffset = (int)reader.ThumbnailOffset; diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs index 6164bd228..53123bfc2 100644 --- a/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs +++ b/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs @@ -75,7 +75,7 @@ namespace ImageSharp { DebugGuard.NotNull(data, nameof(data)); - Collection result = new Collection(); + var result = new Collection(); this.exifData = data; @@ -357,7 +357,7 @@ namespace ImageSharp private TEnum ToEnum(int value, TEnum defaultValue) where TEnum : struct { - TEnum enumValue = (TEnum)(object)value; + var enumValue = (TEnum)(object)value; if (Enum.GetValues(typeof(TEnum)).Cast().Any(v => v.Equals(enumValue))) { return enumValue; @@ -403,7 +403,7 @@ namespace ImageSharp private void GetThumbnail(uint offset) { - Collection values = new Collection(); + var values = new Collection(); this.AddValues(values, offset); foreach (ExifValue value in values) diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifValue.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifValue.cs index 8cd05b53c..a2965917b 100644 --- a/src/ImageSharp/MetaData/Profiles/Exif/ExifValue.cs +++ b/src/ImageSharp/MetaData/Profiles/Exif/ExifValue.cs @@ -39,7 +39,7 @@ namespace ImageSharp } else { - Array array = (Array)other.exifValue; + var array = (Array)other.exifValue; this.exifValue = array.Clone(); } } @@ -264,7 +264,7 @@ namespace ImageSharp return this.ToString(this.exifValue); } - StringBuilder sb = new StringBuilder(); + var sb = new StringBuilder(); foreach (object value in (Array)this.exifValue) { sb.Append(this.ToString(value)); diff --git a/src/ImageSharp/PixelFormats/Alpha8.cs b/src/ImageSharp/PixelFormats/Alpha8.cs index ac2627701..c184ed9cf 100644 --- a/src/ImageSharp/PixelFormats/Alpha8.cs +++ b/src/ImageSharp/PixelFormats/Alpha8.cs @@ -87,7 +87,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzBytes(byte[] bytes, int startIndex) + public void ToXyzBytes(Span bytes, int startIndex) { bytes[startIndex] = 0; bytes[startIndex + 1] = 0; @@ -96,7 +96,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzwBytes(byte[] bytes, int startIndex) + public void ToXyzwBytes(Span bytes, int startIndex) { bytes[startIndex] = 0; bytes[startIndex + 1] = 0; @@ -106,7 +106,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxBytes(byte[] bytes, int startIndex) + public void ToZyxBytes(Span bytes, int startIndex) { bytes[startIndex] = 0; bytes[startIndex + 1] = 0; @@ -115,7 +115,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxwBytes(byte[] bytes, int startIndex) + public void ToZyxwBytes(Span bytes, int startIndex) { bytes[startIndex] = 0; bytes[startIndex + 1] = 0; diff --git a/src/ImageSharp/PixelFormats/Argb32.cs b/src/ImageSharp/PixelFormats/Argb32.cs index 61e860aee..bd47f72f9 100644 --- a/src/ImageSharp/PixelFormats/Argb32.cs +++ b/src/ImageSharp/PixelFormats/Argb32.cs @@ -5,6 +5,7 @@ namespace ImageSharp.PixelFormats { + using System; using System.Numerics; using System.Runtime.CompilerServices; @@ -241,7 +242,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzBytes(byte[] bytes, int startIndex) + public void ToXyzBytes(Span bytes, int startIndex) { bytes[startIndex] = this.R; bytes[startIndex + 1] = this.G; @@ -250,7 +251,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzwBytes(byte[] bytes, int startIndex) + public void ToXyzwBytes(Span bytes, int startIndex) { bytes[startIndex] = this.R; bytes[startIndex + 1] = this.G; @@ -260,7 +261,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxBytes(byte[] bytes, int startIndex) + public void ToZyxBytes(Span bytes, int startIndex) { bytes[startIndex] = this.B; bytes[startIndex + 1] = this.G; @@ -269,7 +270,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxwBytes(byte[] bytes, int startIndex) + public void ToZyxwBytes(Span bytes, int startIndex) { bytes[startIndex] = this.B; bytes[startIndex + 1] = this.G; diff --git a/src/ImageSharp/PixelFormats/Bgr565.cs b/src/ImageSharp/PixelFormats/Bgr565.cs index 813b6fe85..92bbac14c 100644 --- a/src/ImageSharp/PixelFormats/Bgr565.cs +++ b/src/ImageSharp/PixelFormats/Bgr565.cs @@ -110,7 +110,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzBytes(byte[] bytes, int startIndex) + public void ToXyzBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; bytes[startIndex] = (byte)MathF.Round(vector.X); @@ -120,7 +120,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzwBytes(byte[] bytes, int startIndex) + public void ToXyzwBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; bytes[startIndex] = (byte)MathF.Round(vector.X); @@ -131,7 +131,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxBytes(byte[] bytes, int startIndex) + public void ToZyxBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; bytes[startIndex] = (byte)MathF.Round(vector.Z); @@ -141,7 +141,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxwBytes(byte[] bytes, int startIndex) + public void ToZyxwBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; bytes[startIndex] = (byte)MathF.Round(vector.Z); diff --git a/src/ImageSharp/PixelFormats/Bgra4444.cs b/src/ImageSharp/PixelFormats/Bgra4444.cs index 8fb2d0c26..0bac00dfe 100644 --- a/src/ImageSharp/PixelFormats/Bgra4444.cs +++ b/src/ImageSharp/PixelFormats/Bgra4444.cs @@ -101,7 +101,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzBytes(byte[] bytes, int startIndex) + public void ToXyzBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; bytes[startIndex] = (byte)vector.X; @@ -111,7 +111,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzwBytes(byte[] bytes, int startIndex) + public void ToXyzwBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; bytes[startIndex] = (byte)vector.X; @@ -122,7 +122,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxBytes(byte[] bytes, int startIndex) + public void ToZyxBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; bytes[startIndex] = (byte)vector.Z; @@ -132,7 +132,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxwBytes(byte[] bytes, int startIndex) + public void ToZyxwBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; bytes[startIndex] = (byte)vector.Z; diff --git a/src/ImageSharp/PixelFormats/Bgra5551.cs b/src/ImageSharp/PixelFormats/Bgra5551.cs index 26cfa6b8c..f151db644 100644 --- a/src/ImageSharp/PixelFormats/Bgra5551.cs +++ b/src/ImageSharp/PixelFormats/Bgra5551.cs @@ -101,7 +101,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzBytes(byte[] bytes, int startIndex) + public void ToXyzBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; bytes[startIndex] = (byte)vector.X; @@ -111,7 +111,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzwBytes(byte[] bytes, int startIndex) + public void ToXyzwBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; bytes[startIndex] = (byte)vector.X; @@ -122,7 +122,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxBytes(byte[] bytes, int startIndex) + public void ToZyxBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; bytes[startIndex] = (byte)vector.Z; @@ -132,7 +132,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxwBytes(byte[] bytes, int startIndex) + public void ToZyxwBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; bytes[startIndex] = (byte)vector.Z; diff --git a/src/ImageSharp/PixelFormats/Byte4.cs b/src/ImageSharp/PixelFormats/Byte4.cs index 951b7c3cb..264bc7497 100644 --- a/src/ImageSharp/PixelFormats/Byte4.cs +++ b/src/ImageSharp/PixelFormats/Byte4.cs @@ -102,7 +102,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzBytes(byte[] bytes, int startIndex) + public void ToXyzBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4(); bytes[startIndex] = (byte)vector.X; @@ -112,7 +112,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzwBytes(byte[] bytes, int startIndex) + public void ToXyzwBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4(); bytes[startIndex] = (byte)vector.X; @@ -123,7 +123,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxBytes(byte[] bytes, int startIndex) + public void ToZyxBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4(); bytes[startIndex] = (byte)vector.Z; @@ -133,7 +133,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxwBytes(byte[] bytes, int startIndex) + public void ToZyxwBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4(); bytes[startIndex] = (byte)vector.Z; diff --git a/src/ImageSharp/PixelFormats/HalfSingle.cs b/src/ImageSharp/PixelFormats/HalfSingle.cs index e9f02d34e..4cc9acc22 100644 --- a/src/ImageSharp/PixelFormats/HalfSingle.cs +++ b/src/ImageSharp/PixelFormats/HalfSingle.cs @@ -5,6 +5,7 @@ namespace ImageSharp.PixelFormats { + using System; using System.Numerics; using System.Runtime.CompilerServices; @@ -110,7 +111,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzBytes(byte[] bytes, int startIndex) + public void ToXyzBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4(); vector *= MaxBytes; @@ -124,7 +125,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzwBytes(byte[] bytes, int startIndex) + public void ToXyzwBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4(); vector *= MaxBytes; @@ -139,7 +140,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxBytes(byte[] bytes, int startIndex) + public void ToZyxBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4(); vector *= MaxBytes; @@ -153,7 +154,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxwBytes(byte[] bytes, int startIndex) + public void ToZyxwBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4(); vector *= MaxBytes; diff --git a/src/ImageSharp/PixelFormats/HalfVector2.cs b/src/ImageSharp/PixelFormats/HalfVector2.cs index 8813fd455..f490f7169 100644 --- a/src/ImageSharp/PixelFormats/HalfVector2.cs +++ b/src/ImageSharp/PixelFormats/HalfVector2.cs @@ -5,6 +5,7 @@ namespace ImageSharp.PixelFormats { + using System; using System.Numerics; using System.Runtime.CompilerServices; @@ -124,7 +125,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzBytes(byte[] bytes, int startIndex) + public void ToXyzBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4(); vector *= MaxBytes; @@ -138,7 +139,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzwBytes(byte[] bytes, int startIndex) + public void ToXyzwBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4(); vector *= MaxBytes; @@ -153,7 +154,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxBytes(byte[] bytes, int startIndex) + public void ToZyxBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4(); vector *= MaxBytes; @@ -167,7 +168,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxwBytes(byte[] bytes, int startIndex) + public void ToZyxwBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4(); vector *= MaxBytes; diff --git a/src/ImageSharp/PixelFormats/HalfVector4.cs b/src/ImageSharp/PixelFormats/HalfVector4.cs index e8c78047e..7c496c161 100644 --- a/src/ImageSharp/PixelFormats/HalfVector4.cs +++ b/src/ImageSharp/PixelFormats/HalfVector4.cs @@ -5,6 +5,7 @@ namespace ImageSharp.PixelFormats { + using System; using System.Numerics; using System.Runtime.CompilerServices; @@ -117,7 +118,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzBytes(byte[] bytes, int startIndex) + public void ToXyzBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4(); vector *= MaxBytes; @@ -131,7 +132,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzwBytes(byte[] bytes, int startIndex) + public void ToXyzwBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4(); vector *= MaxBytes; @@ -146,7 +147,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxBytes(byte[] bytes, int startIndex) + public void ToZyxBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4(); vector *= MaxBytes; @@ -160,7 +161,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxwBytes(byte[] bytes, int startIndex) + public void ToZyxwBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4(); vector *= MaxBytes; diff --git a/src/ImageSharp/PixelFormats/IPixel.cs b/src/ImageSharp/PixelFormats/IPixel.cs index 9a8d9730a..030cb93f4 100644 --- a/src/ImageSharp/PixelFormats/IPixel.cs +++ b/src/ImageSharp/PixelFormats/IPixel.cs @@ -56,7 +56,7 @@ namespace ImageSharp.PixelFormats /// /// The bytes to set the color in. /// The starting index of the . - void ToXyzBytes(byte[] bytes, int startIndex); + void ToXyzBytes(Span bytes, int startIndex); /// /// Expands the packed representation into a given byte array. @@ -64,7 +64,7 @@ namespace ImageSharp.PixelFormats /// /// The bytes to set the color in. /// The starting index of the . - void ToXyzwBytes(byte[] bytes, int startIndex); + void ToXyzwBytes(Span bytes, int startIndex); /// /// Expands the packed representation into a given byte array. @@ -72,7 +72,7 @@ namespace ImageSharp.PixelFormats /// /// The bytes to set the color in. /// The starting index of the . - void ToZyxBytes(byte[] bytes, int startIndex); + void ToZyxBytes(Span bytes, int startIndex); /// /// Expands the packed representation into a given byte array. @@ -80,6 +80,6 @@ namespace ImageSharp.PixelFormats /// /// The bytes to set the color in. /// The starting index of the . - void ToZyxwBytes(byte[] bytes, int startIndex); + void ToZyxwBytes(Span bytes, int startIndex); } } \ No newline at end of file diff --git a/src/ImageSharp/PixelFormats/NormalizedByte2.cs b/src/ImageSharp/PixelFormats/NormalizedByte2.cs index 93226342e..47a4f3005 100644 --- a/src/ImageSharp/PixelFormats/NormalizedByte2.cs +++ b/src/ImageSharp/PixelFormats/NormalizedByte2.cs @@ -134,7 +134,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzBytes(byte[] bytes, int startIndex) + public void ToXyzBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4(); vector *= Half; @@ -150,7 +150,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzwBytes(byte[] bytes, int startIndex) + public void ToXyzwBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4(); vector *= Half; @@ -167,7 +167,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxBytes(byte[] bytes, int startIndex) + public void ToZyxBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4(); vector *= Half; @@ -183,7 +183,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxwBytes(byte[] bytes, int startIndex) + public void ToZyxwBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4(); vector *= Half; diff --git a/src/ImageSharp/PixelFormats/NormalizedByte4.cs b/src/ImageSharp/PixelFormats/NormalizedByte4.cs index 66a79fefc..4559bd082 100644 --- a/src/ImageSharp/PixelFormats/NormalizedByte4.cs +++ b/src/ImageSharp/PixelFormats/NormalizedByte4.cs @@ -127,7 +127,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzBytes(byte[] bytes, int startIndex) + public void ToXyzBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4(); vector *= Half; @@ -143,7 +143,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzwBytes(byte[] bytes, int startIndex) + public void ToXyzwBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4(); vector *= Half; @@ -160,7 +160,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxBytes(byte[] bytes, int startIndex) + public void ToZyxBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4(); vector *= Half; @@ -176,7 +176,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxwBytes(byte[] bytes, int startIndex) + public void ToZyxwBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4(); vector *= Half; diff --git a/src/ImageSharp/PixelFormats/NormalizedShort2.cs b/src/ImageSharp/PixelFormats/NormalizedShort2.cs index 99e5a98c0..648b68905 100644 --- a/src/ImageSharp/PixelFormats/NormalizedShort2.cs +++ b/src/ImageSharp/PixelFormats/NormalizedShort2.cs @@ -5,6 +5,7 @@ namespace ImageSharp.PixelFormats { + using System; using System.Numerics; using System.Runtime.CompilerServices; @@ -120,7 +121,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzBytes(byte[] bytes, int startIndex) + public void ToXyzBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4(); vector *= Half; @@ -136,7 +137,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzwBytes(byte[] bytes, int startIndex) + public void ToXyzwBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4(); vector *= Half; @@ -153,7 +154,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxBytes(byte[] bytes, int startIndex) + public void ToZyxBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4(); vector *= Half; @@ -169,7 +170,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxwBytes(byte[] bytes, int startIndex) + public void ToZyxwBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4(); vector *= Half; diff --git a/src/ImageSharp/PixelFormats/NormalizedShort4.cs b/src/ImageSharp/PixelFormats/NormalizedShort4.cs index 932ab97cf..7b520aace 100644 --- a/src/ImageSharp/PixelFormats/NormalizedShort4.cs +++ b/src/ImageSharp/PixelFormats/NormalizedShort4.cs @@ -5,6 +5,7 @@ namespace ImageSharp.PixelFormats { + using System; using System.Numerics; using System.Runtime.CompilerServices; @@ -128,7 +129,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzBytes(byte[] bytes, int startIndex) + public void ToXyzBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4(); vector *= Half; @@ -144,7 +145,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzwBytes(byte[] bytes, int startIndex) + public void ToXyzwBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4(); vector *= Half; @@ -161,7 +162,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxBytes(byte[] bytes, int startIndex) + public void ToZyxBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4(); vector *= Half; @@ -177,7 +178,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxwBytes(byte[] bytes, int startIndex) + public void ToZyxwBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4(); vector *= Half; diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultAddPixelBlender{TPixel}.cs b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultAddPixelBlender{TPixel}.cs index ab3aee041..261a98674 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultAddPixelBlender{TPixel}.cs +++ b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultAddPixelBlender{TPixel}.cs @@ -7,6 +7,8 @@ namespace ImageSharp.PixelFormats.PixelBlenders { using System; using System.Numerics; + + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// @@ -28,7 +30,7 @@ namespace ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(BufferSpan destination, BufferSpan background, BufferSpan source, BufferSpan amount) + public override void Blend(Span destination, Span background, Span source, Span amount) { Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); @@ -36,9 +38,9 @@ namespace ImageSharp.PixelFormats.PixelBlenders using (Buffer buffer = new Buffer(destination.Length * 3)) { - BufferSpan destinationSpan = buffer.Slice(0, destination.Length); - BufferSpan backgroundSpan = buffer.Slice(destination.Length, destination.Length); - BufferSpan sourceSpan = buffer.Slice(destination.Length * 2, destination.Length); + Span destinationSpan = buffer.Slice(0, destination.Length); + Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); + Span sourceSpan = buffer.Slice(destination.Length * 2, destination.Length); PixelOperations.Instance.ToVector4(background, backgroundSpan, destination.Length); PixelOperations.Instance.ToVector4(source, sourceSpan, destination.Length); diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultDarkenPixelBlender{TPixel}.cs b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultDarkenPixelBlender{TPixel}.cs index e0ff80b66..bca99e2f0 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultDarkenPixelBlender{TPixel}.cs +++ b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultDarkenPixelBlender{TPixel}.cs @@ -7,6 +7,8 @@ namespace ImageSharp.PixelFormats.PixelBlenders { using System; using System.Numerics; + + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// @@ -28,7 +30,7 @@ namespace ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(BufferSpan destination, BufferSpan background, BufferSpan source, BufferSpan amount) + public override void Blend(Span destination, Span background, Span source, Span amount) { Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); @@ -36,9 +38,9 @@ namespace ImageSharp.PixelFormats.PixelBlenders using (Buffer buffer = new Buffer(destination.Length * 3)) { - BufferSpan destinationSpan = buffer.Slice(0, destination.Length); - BufferSpan backgroundSpan = buffer.Slice(destination.Length, destination.Length); - BufferSpan sourceSpan = buffer.Slice(destination.Length * 2, destination.Length); + Span destinationSpan = buffer.Slice(0, destination.Length); + Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); + Span sourceSpan = buffer.Slice(destination.Length * 2, destination.Length); PixelOperations.Instance.ToVector4(background, backgroundSpan, destination.Length); PixelOperations.Instance.ToVector4(source, sourceSpan, destination.Length); diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultHardLightPixelBlender{TPixel}.cs b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultHardLightPixelBlender{TPixel}.cs index cec0dc0db..646423cff 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultHardLightPixelBlender{TPixel}.cs +++ b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultHardLightPixelBlender{TPixel}.cs @@ -7,6 +7,8 @@ namespace ImageSharp.PixelFormats.PixelBlenders { using System; using System.Numerics; + + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// @@ -28,7 +30,7 @@ namespace ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(BufferSpan destination, BufferSpan background, BufferSpan source, BufferSpan amount) + public override void Blend(Span destination, Span background, Span source, Span amount) { Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); @@ -36,9 +38,9 @@ namespace ImageSharp.PixelFormats.PixelBlenders using (Buffer buffer = new Buffer(destination.Length * 3)) { - BufferSpan destinationSpan = buffer.Slice(0, destination.Length); - BufferSpan backgroundSpan = buffer.Slice(destination.Length, destination.Length); - BufferSpan sourceSpan = buffer.Slice(destination.Length * 2, destination.Length); + Span destinationSpan = buffer.Slice(0, destination.Length); + Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); + Span sourceSpan = buffer.Slice(destination.Length * 2, destination.Length); PixelOperations.Instance.ToVector4(background, backgroundSpan, destination.Length); PixelOperations.Instance.ToVector4(source, sourceSpan, destination.Length); diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultLightenPixelBlender{TPixel}.cs b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultLightenPixelBlender{TPixel}.cs index 32cd20650..55ad81e7a 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultLightenPixelBlender{TPixel}.cs +++ b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultLightenPixelBlender{TPixel}.cs @@ -7,6 +7,8 @@ namespace ImageSharp.PixelFormats.PixelBlenders { using System; using System.Numerics; + + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// @@ -28,7 +30,7 @@ namespace ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(BufferSpan destination, BufferSpan background, BufferSpan source, BufferSpan amount) + public override void Blend(Span destination, Span background, Span source, Span amount) { Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); @@ -36,9 +38,9 @@ namespace ImageSharp.PixelFormats.PixelBlenders using (Buffer buffer = new Buffer(destination.Length * 3)) { - BufferSpan destinationSpan = buffer.Slice(0, destination.Length); - BufferSpan backgroundSpan = buffer.Slice(destination.Length, destination.Length); - BufferSpan sourceSpan = buffer.Slice(destination.Length * 2, destination.Length); + Span destinationSpan = buffer.Slice(0, destination.Length); + Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); + Span sourceSpan = buffer.Slice(destination.Length * 2, destination.Length); PixelOperations.Instance.ToVector4(background, backgroundSpan, destination.Length); PixelOperations.Instance.ToVector4(source, sourceSpan, destination.Length); diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultMultiplyPixelBlender{TPixel}.cs b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultMultiplyPixelBlender{TPixel}.cs index 7e0137018..e21efaed0 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultMultiplyPixelBlender{TPixel}.cs +++ b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultMultiplyPixelBlender{TPixel}.cs @@ -7,6 +7,8 @@ namespace ImageSharp.PixelFormats.PixelBlenders { using System; using System.Numerics; + + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// @@ -28,7 +30,7 @@ namespace ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(BufferSpan destination, BufferSpan background, BufferSpan source, BufferSpan amount) + public override void Blend(Span destination, Span background, Span source, Span amount) { Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); @@ -36,9 +38,9 @@ namespace ImageSharp.PixelFormats.PixelBlenders using (Buffer buffer = new Buffer(destination.Length * 3)) { - BufferSpan destinationSpan = buffer.Slice(0, destination.Length); - BufferSpan backgroundSpan = buffer.Slice(destination.Length, destination.Length); - BufferSpan sourceSpan = buffer.Slice(destination.Length * 2, destination.Length); + Span destinationSpan = buffer.Slice(0, destination.Length); + Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); + Span sourceSpan = buffer.Slice(destination.Length * 2, destination.Length); PixelOperations.Instance.ToVector4(background, backgroundSpan, destination.Length); PixelOperations.Instance.ToVector4(source, sourceSpan, destination.Length); diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultNormalPixelBlender{TPixel}.cs b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultNormalPixelBlender{TPixel}.cs index 47bb084ca..9d63d11e0 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultNormalPixelBlender{TPixel}.cs +++ b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultNormalPixelBlender{TPixel}.cs @@ -7,6 +7,8 @@ namespace ImageSharp.PixelFormats.PixelBlenders { using System; using System.Numerics; + + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// @@ -28,7 +30,7 @@ namespace ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(BufferSpan destination, BufferSpan background, BufferSpan source, BufferSpan amount) + public override void Blend(Span destination, Span background, Span source, Span amount) { Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); @@ -36,9 +38,9 @@ namespace ImageSharp.PixelFormats.PixelBlenders using (Buffer buffer = new Buffer(destination.Length * 3)) { - BufferSpan destinationSpan = buffer.Slice(0, destination.Length); - BufferSpan backgroundSpan = buffer.Slice(destination.Length, destination.Length); - BufferSpan sourceSpan = buffer.Slice(destination.Length * 2, destination.Length); + Span destinationSpan = buffer.Slice(0, destination.Length); + Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); + Span sourceSpan = buffer.Slice(destination.Length * 2, destination.Length); PixelOperations.Instance.ToVector4(background, backgroundSpan, destination.Length); PixelOperations.Instance.ToVector4(source, sourceSpan, destination.Length); diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultOverlayPixelBlender{TPixel}.cs b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultOverlayPixelBlender{TPixel}.cs index fcb56e3dc..8172909ec 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultOverlayPixelBlender{TPixel}.cs +++ b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultOverlayPixelBlender{TPixel}.cs @@ -7,6 +7,8 @@ namespace ImageSharp.PixelFormats.PixelBlenders { using System; using System.Numerics; + + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// @@ -28,7 +30,7 @@ namespace ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(BufferSpan destination, BufferSpan background, BufferSpan source, BufferSpan amount) + public override void Blend(Span destination, Span background, Span source, Span amount) { Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); @@ -36,9 +38,9 @@ namespace ImageSharp.PixelFormats.PixelBlenders using (Buffer buffer = new Buffer(destination.Length * 3)) { - BufferSpan destinationSpan = buffer.Slice(0, destination.Length); - BufferSpan backgroundSpan = buffer.Slice(destination.Length, destination.Length); - BufferSpan sourceSpan = buffer.Slice(destination.Length * 2, destination.Length); + Span destinationSpan = buffer.Slice(0, destination.Length); + Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); + Span sourceSpan = buffer.Slice(destination.Length * 2, destination.Length); PixelOperations.Instance.ToVector4(background, backgroundSpan, destination.Length); PixelOperations.Instance.ToVector4(source, sourceSpan, destination.Length); diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultScreenPixelBlender{TPixel}.cs b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultScreenPixelBlender{TPixel}.cs index df0de293c..8405c3946 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultScreenPixelBlender{TPixel}.cs +++ b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultScreenPixelBlender{TPixel}.cs @@ -7,6 +7,8 @@ namespace ImageSharp.PixelFormats.PixelBlenders { using System; using System.Numerics; + + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// @@ -28,7 +30,7 @@ namespace ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(BufferSpan destination, BufferSpan background, BufferSpan source, BufferSpan amount) + public override void Blend(Span destination, Span background, Span source, Span amount) { Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); @@ -36,9 +38,9 @@ namespace ImageSharp.PixelFormats.PixelBlenders using (Buffer buffer = new Buffer(destination.Length * 3)) { - BufferSpan destinationSpan = buffer.Slice(0, destination.Length); - BufferSpan backgroundSpan = buffer.Slice(destination.Length, destination.Length); - BufferSpan sourceSpan = buffer.Slice(destination.Length * 2, destination.Length); + Span destinationSpan = buffer.Slice(0, destination.Length); + Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); + Span sourceSpan = buffer.Slice(destination.Length * 2, destination.Length); PixelOperations.Instance.ToVector4(background, backgroundSpan, destination.Length); PixelOperations.Instance.ToVector4(source, sourceSpan, destination.Length); diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultSubstractPixelBlender{TPixel}.cs b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultSubstractPixelBlender{TPixel}.cs index 415ac04b2..ab44cb760 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultSubstractPixelBlender{TPixel}.cs +++ b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultSubstractPixelBlender{TPixel}.cs @@ -7,6 +7,8 @@ namespace ImageSharp.PixelFormats.PixelBlenders { using System; using System.Numerics; + + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// @@ -28,7 +30,7 @@ namespace ImageSharp.PixelFormats.PixelBlenders } /// - public override void Blend(BufferSpan destination, BufferSpan background, BufferSpan source, BufferSpan amount) + public override void Blend(Span destination, Span background, Span source, Span amount) { Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length)); Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length)); @@ -36,9 +38,9 @@ namespace ImageSharp.PixelFormats.PixelBlenders using (Buffer buffer = new Buffer(destination.Length * 3)) { - BufferSpan destinationSpan = buffer.Slice(0, destination.Length); - BufferSpan backgroundSpan = buffer.Slice(destination.Length, destination.Length); - BufferSpan sourceSpan = buffer.Slice(destination.Length * 2, destination.Length); + Span destinationSpan = buffer.Slice(0, destination.Length); + Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); + Span sourceSpan = buffer.Slice(destination.Length * 2, destination.Length); PixelOperations.Instance.ToVector4(background, backgroundSpan, destination.Length); PixelOperations.Instance.ToVector4(source, sourceSpan, destination.Length); diff --git a/src/ImageSharp/PixelFormats/PixelBlender{TPixel}.cs b/src/ImageSharp/PixelFormats/PixelBlender{TPixel}.cs index 23340a60a..1a1d1cd05 100644 --- a/src/ImageSharp/PixelFormats/PixelBlender{TPixel}.cs +++ b/src/ImageSharp/PixelFormats/PixelBlender{TPixel}.cs @@ -5,6 +5,8 @@ namespace ImageSharp.PixelFormats { + using System; + /// /// Abstract base class for calling pixel composition functions /// @@ -34,6 +36,6 @@ namespace ImageSharp.PixelFormats /// A value between 0 and 1 indicating the weight of the second source vector. /// At amount = 0, "from" is returned, at amount = 1, "to" is returned. /// - public abstract void Blend(BufferSpan destination, BufferSpan background, BufferSpan source, BufferSpan amount); + public abstract void Blend(Span destination, Span background, Span source, Span amount); } } diff --git a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs index 207040521..993a11232 100644 --- a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs +++ b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs @@ -5,6 +5,7 @@ namespace ImageSharp.PixelFormats { + using System; using System.Numerics; using System.Runtime.CompilerServices; @@ -24,11 +25,14 @@ namespace ImageSharp.PixelFormats /// /// Bulk version of /// - /// The to the source vectors. - /// The to the destination colors. + /// 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(Span sourceVectors, Span destColors, int count) { + Guard.MustBeSizedAtLeast(sourceVectors, count, nameof(sourceVectors)); + Guard.MustBeSizedAtLeast(destColors, count, nameof(destColors)); + ref Vector4 sourceRef = ref sourceVectors.DangerousGetPinnableReference(); ref TPixel destRef = ref destColors.DangerousGetPinnableReference(); @@ -43,11 +47,14 @@ namespace ImageSharp.PixelFormats /// /// Bulk version of . /// - /// The to the source colors. - /// The to the destination vectors. + /// 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(Span sourceColors, Span destVectors, int count) { + Guard.MustBeSizedAtLeast(sourceColors, count, nameof(sourceColors)); + Guard.MustBeSizedAtLeast(destVectors, count, nameof(destVectors)); + ref TPixel sourceRef = ref sourceColors.DangerousGetPinnableReference(); ref Vector4 destRef = ref destVectors.DangerousGetPinnableReference(); @@ -62,11 +69,14 @@ namespace ImageSharp.PixelFormats /// /// Bulk version of that converts data in . /// - /// The to the source bytes. - /// The to the destination colors. + /// 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(Span sourceBytes, Span destColors, int count) { + Guard.MustBeSizedAtLeast(sourceBytes, count * 3, nameof(sourceBytes)); + Guard.MustBeSizedAtLeast(destColors, count, nameof(destColors)); + ref byte sourceRef = ref sourceBytes.DangerousGetPinnableReference(); ref TPixel destRef = ref destColors.DangerousGetPinnableReference(); @@ -83,31 +93,36 @@ namespace ImageSharp.PixelFormats } /// - /// Bulk version of . + /// Bulk version of . /// - /// The to the source colors. - /// The to the destination bytes. + /// 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(Span sourceColors, Span destBytes, int count) { + Guard.MustBeSizedAtLeast(sourceColors, count, nameof(sourceColors)); + Guard.MustBeSizedAtLeast(destBytes, count * 3, nameof(destBytes)); + ref TPixel sourceRef = ref sourceColors.DangerousGetPinnableReference(); - byte[] dest = destBytes.Array; for (int i = 0; i < count; i++) { ref TPixel sp = ref Unsafe.Add(ref sourceRef, i); - sp.ToXyzBytes(dest, destBytes.Start + (i * 3)); + sp.ToXyzBytes(destBytes, i * 3); } } /// /// Bulk version of that converts data in . /// - /// The to the source bytes. - /// The to the destination colors. + /// 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(Span sourceBytes, Span destColors, int count) { + Guard.MustBeSizedAtLeast(sourceBytes, count * 4, nameof(sourceBytes)); + Guard.MustBeSizedAtLeast(destColors, count, nameof(destColors)); + ref byte sourceRef = ref sourceBytes.DangerousGetPinnableReference(); ref TPixel destRef = ref destColors.DangerousGetPinnableReference(); @@ -124,31 +139,36 @@ namespace ImageSharp.PixelFormats } /// - /// Bulk version of . + /// Bulk version of /// - /// The to the source colors. - /// The to the destination bytes. + /// 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(Span sourceColors, Span destBytes, int count) { + Guard.MustBeSizedAtLeast(sourceColors, count, nameof(sourceColors)); + Guard.MustBeSizedAtLeast(destBytes, count * 4, nameof(destBytes)); + ref TPixel sourceRef = ref sourceColors.DangerousGetPinnableReference(); - byte[] dest = destBytes.Array; for (int i = 0; i < count; i++) { ref TPixel sp = ref Unsafe.Add(ref sourceRef, i); - sp.ToXyzwBytes(dest, destBytes.Start + (i * 4)); + sp.ToXyzwBytes(destBytes, i * 4); } } /// /// Bulk version of that converts data in . /// - /// The to the source bytes. - /// The to the destination colors. + /// 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(Span sourceBytes, Span destColors, int count) { + Guard.MustBeSizedAtLeast(sourceBytes, count * 3, nameof(sourceBytes)); + Guard.MustBeSizedAtLeast(destColors, count, nameof(destColors)); + ref byte sourceRef = ref sourceBytes.DangerousGetPinnableReference(); ref TPixel destRef = ref destColors.DangerousGetPinnableReference(); @@ -165,31 +185,36 @@ namespace ImageSharp.PixelFormats } /// - /// Bulk version of . + /// Bulk version of . /// - /// The to the source colors. - /// The to the destination bytes. + /// 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(Span sourceColors, Span destBytes, int count) { + Guard.MustBeSizedAtLeast(sourceColors, count, nameof(sourceColors)); + Guard.MustBeSizedAtLeast(destBytes, count * 3, nameof(destBytes)); + ref TPixel sourceRef = ref sourceColors.DangerousGetPinnableReference(); - byte[] dest = destBytes.Array; for (int i = 0; i < count; i++) { ref TPixel sp = ref Unsafe.Add(ref sourceRef, i); - sp.ToZyxBytes(dest, destBytes.Start + (i * 3)); + sp.ToZyxBytes(destBytes, i * 3); } } /// /// Bulk version of that converts data in . /// - /// The to the source bytes. - /// The to the destination colors. + /// 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(Span sourceBytes, Span destColors, int count) { + Guard.MustBeSizedAtLeast(sourceBytes, count * 4, nameof(sourceBytes)); + Guard.MustBeSizedAtLeast(destColors, count, nameof(destColors)); + ref byte sourceRef = ref sourceBytes.DangerousGetPinnableReference(); ref TPixel destRef = ref destColors.DangerousGetPinnableReference(); @@ -206,20 +231,22 @@ namespace ImageSharp.PixelFormats } /// - /// Bulk version of . + /// Bulk version of . /// - /// The to the source colors. - /// The to the destination bytes. + /// 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(Span sourceColors, Span destBytes, int count) { + Guard.MustBeSizedAtLeast(sourceColors, count, nameof(sourceColors)); + Guard.MustBeSizedAtLeast(destBytes, count * 4, nameof(destBytes)); + ref TPixel sourceRef = ref sourceColors.DangerousGetPinnableReference(); - byte[] dest = destBytes.Array; for (int i = 0; i < count; i++) { ref TPixel sp = ref Unsafe.Add(ref sourceRef, i); - sp.ToZyxwBytes(dest, destBytes.Start + (i * 4)); + sp.ToZyxwBytes(destBytes, i * 4); } } } diff --git a/src/ImageSharp/PixelFormats/README.md b/src/ImageSharp/PixelFormats/README.md index 61500de68..c7aa01295 100644 --- a/src/ImageSharp/PixelFormats/README.md +++ b/src/ImageSharp/PixelFormats/README.md @@ -1,3 +1,7 @@ Pixel formats adapted and extended from: -https://github.com/MonoGame/MonoGame \ No newline at end of file +https://github.com/MonoGame/MonoGame + +Rgba32 is our default format. As such it positioned within the ImageSharp root namespace to ensure visibility of the format. + +All other pixel formats should be positioned within ImageSharp.PixelFormats to reduce intellisense burden. \ No newline at end of file diff --git a/src/ImageSharp/PixelFormats/Rg32.cs b/src/ImageSharp/PixelFormats/Rg32.cs index 3e23777f6..ea7d8729b 100644 --- a/src/ImageSharp/PixelFormats/Rg32.cs +++ b/src/ImageSharp/PixelFormats/Rg32.cs @@ -114,7 +114,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzBytes(byte[] bytes, int startIndex) + public void ToXyzBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; @@ -125,7 +125,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzwBytes(byte[] bytes, int startIndex) + public void ToXyzwBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; @@ -137,7 +137,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxBytes(byte[] bytes, int startIndex) + public void ToZyxBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; @@ -148,7 +148,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxwBytes(byte[] bytes, int startIndex) + public void ToZyxwBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; diff --git a/src/ImageSharp/PixelFormats/Rgba1010102.cs b/src/ImageSharp/PixelFormats/Rgba1010102.cs index 747112fd8..ca7b74fbb 100644 --- a/src/ImageSharp/PixelFormats/Rgba1010102.cs +++ b/src/ImageSharp/PixelFormats/Rgba1010102.cs @@ -108,7 +108,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzBytes(byte[] bytes, int startIndex) + public void ToXyzBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; @@ -119,7 +119,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzwBytes(byte[] bytes, int startIndex) + public void ToXyzwBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; @@ -131,7 +131,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxBytes(byte[] bytes, int startIndex) + public void ToZyxBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; @@ -142,7 +142,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxwBytes(byte[] bytes, int startIndex) + public void ToZyxwBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; diff --git a/src/ImageSharp/PixelFormats/Rgba32.Definitions.cs b/src/ImageSharp/PixelFormats/Rgba32.Definitions.cs index be02d0875..ab4c2ea60 100644 --- a/src/ImageSharp/PixelFormats/Rgba32.Definitions.cs +++ b/src/ImageSharp/PixelFormats/Rgba32.Definitions.cs @@ -3,8 +3,10 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.PixelFormats +namespace ImageSharp { + using ImageSharp.PixelFormats; + /// /// Provides standardized deifinitions for named colors. /// diff --git a/src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs b/src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs index ff284e625..2ba663603 100644 --- a/src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs @@ -3,13 +3,16 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.PixelFormats +namespace ImageSharp { using System; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; + using ImageSharp.Memory; + using ImageSharp.PixelFormats; + /// /// Provides optimized overrides for bulk operations. /// @@ -24,8 +27,8 @@ namespace ImageSharp.PixelFormats /// SIMD optimized bulk implementation of /// that works only with `count` divisible by . /// - /// The to the source colors. - /// The to the dstination vectors. + /// The to the source colors. + /// The to the dstination vectors. /// The number of pixels to convert. /// /// Implementation adapted from: @@ -37,18 +40,16 @@ namespace ImageSharp.PixelFormats /// https://github.com/dotnet/corefx/issues/15957 /// /// - internal static unsafe void ToVector4SimdAligned(BufferSpan sourceColors, BufferSpan destVectors, int count) + internal static void ToVector4SimdAligned(Span sourceColors, Span destVectors, int count) { if (!Vector.IsHardwareAccelerated) { throw new InvalidOperationException( - "Rgba32.BulkOperations.ToVector4SimdAligned() should not be called when Vector.IsHardwareAccelerated == false!"); + "Rgba32.PixelOperations.ToVector4SimdAligned() should not be called when Vector.IsHardwareAccelerated == false!"); } - int vecSize = Vector.Count; - DebugGuard.IsTrue( - count % vecSize == 0, + count % Vector.Count == 0, nameof(count), "Argument 'count' should divisible by Vector.Count!"); @@ -59,44 +60,42 @@ namespace ImageSharp.PixelFormats int unpackedRawCount = count * 4; - ref uint src = ref Unsafe.As(ref sourceColors.DangerousGetPinnableReference()); + ref uint sourceBase = ref Unsafe.As(ref sourceColors.DangerousGetPinnableReference()); + ref UnpackedRGBA destBaseAsUnpacked = ref Unsafe.As(ref destVectors.DangerousGetPinnableReference()); + ref Vector destBaseAsUInt = ref Unsafe.As>(ref destBaseAsUnpacked); + ref Vector destBaseAsFloat = ref Unsafe.As>(ref destBaseAsUnpacked); - using (Buffer tempBuf = new Buffer( - unpackedRawCount + Vector.Count)) + for (int i = 0; i < count; i++) { - uint[] temp = tempBuf.Array; - float[] fTemp = Unsafe.As(temp); - - ref UnpackedRGBA tempBase = ref Unsafe.As(ref tempBuf[0]); + uint sVal = Unsafe.Add(ref sourceBase, i); + ref UnpackedRGBA dst = ref Unsafe.Add(ref destBaseAsUnpacked, i); - for (int i = 0; i < count; i++) - { - uint sVal = Unsafe.Add(ref src, i); - ref UnpackedRGBA dst = ref Unsafe.Add(ref tempBase, i); + // This call is the bottleneck now: + dst.Load(sVal); + } - // This call is the bottleneck now: - dst.Load(sVal); - } + int numOfVectors = unpackedRawCount / Vector.Count; - for (int i = 0; i < unpackedRawCount; i += vecSize) - { - Vector vi = new Vector(temp, i); + for (int i = 0; i < numOfVectors; i++) + { + Vector vi = Unsafe.Add(ref destBaseAsUInt, i); - vi &= mask; - vi |= magicInt; + vi &= mask; + vi |= magicInt; - Vector vf = Vector.AsVectorSingle(vi); - vf = (vf - magicFloat) * bVec; - vf.CopyTo(fTemp, i); - } + Vector vf = Vector.AsVectorSingle(vi); + vf = (vf - magicFloat) * bVec; - BufferSpan.Copy(tempBuf.Span.AsBytes(), destVectors.AsBytes(), unpackedRawCount * sizeof(uint)); + Unsafe.Add(ref destBaseAsFloat, i) = vf; } } /// - internal override void ToVector4(BufferSpan sourceColors, BufferSpan destVectors, int count) + internal override void ToVector4(Span sourceColors, Span destVectors, int count) { + Guard.MustBeSizedAtLeast(sourceColors, count, nameof(sourceColors)); + Guard.MustBeSizedAtLeast(destVectors, count, nameof(destVectors)); + if (count < 256 || !Vector.IsHardwareAccelerated) { // Doesn't worth to bother with SIMD: @@ -122,8 +121,11 @@ namespace ImageSharp.PixelFormats } /// - internal override void PackFromXyzBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) + internal override void PackFromXyzBytes(Span sourceBytes, Span destColors, int count) { + Guard.MustBeSizedAtLeast(sourceBytes, count * 3, nameof(sourceBytes)); + Guard.MustBeSizedAtLeast(destColors, count, nameof(destColors)); + ref RGB24 sourceRef = ref Unsafe.As(ref sourceBytes.DangerousGetPinnableReference()); ref Rgba32 destRef = ref destColors.DangerousGetPinnableReference(); @@ -138,8 +140,11 @@ namespace ImageSharp.PixelFormats } /// - internal override void ToXyzBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) + internal override void ToXyzBytes(Span sourceColors, Span destBytes, int count) { + Guard.MustBeSizedAtLeast(sourceColors, count, nameof(sourceColors)); + Guard.MustBeSizedAtLeast(destBytes, count * 3, nameof(destBytes)); + ref Rgba32 sourceRef = ref sourceColors.DangerousGetPinnableReference(); ref RGB24 destRef = ref Unsafe.As(ref destBytes.DangerousGetPinnableReference()); @@ -153,20 +158,29 @@ namespace ImageSharp.PixelFormats } /// - internal override unsafe void PackFromXyzwBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) + internal override unsafe void PackFromXyzwBytes(Span sourceBytes, Span destColors, int count) { - BufferSpan.Copy(sourceBytes, destColors.AsBytes(), count * sizeof(Rgba32)); + Guard.MustBeSizedAtLeast(sourceBytes, count * 4, nameof(sourceBytes)); + Guard.MustBeSizedAtLeast(destColors, count, nameof(destColors)); + + SpanHelper.Copy(sourceBytes, destColors.AsBytes(), count * sizeof(Rgba32)); } /// - internal override unsafe void ToXyzwBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) + internal override unsafe void ToXyzwBytes(Span sourceColors, Span destBytes, int count) { - BufferSpan.Copy(sourceColors.AsBytes(), destBytes, count * sizeof(Rgba32)); + Guard.MustBeSizedAtLeast(sourceColors, count, nameof(sourceColors)); + Guard.MustBeSizedAtLeast(destBytes, count * 4, nameof(destBytes)); + + SpanHelper.Copy(sourceColors.AsBytes(), destBytes, count * sizeof(Rgba32)); } /// - internal override void PackFromZyxBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) + internal override void PackFromZyxBytes(Span sourceBytes, Span destColors, int count) { + Guard.MustBeSizedAtLeast(sourceBytes, count * 3, nameof(sourceBytes)); + Guard.MustBeSizedAtLeast(destColors, count, nameof(destColors)); + ref RGB24 sourceRef = ref Unsafe.As(ref sourceBytes.DangerousGetPinnableReference()); ref Rgba32 destRef = ref destColors.DangerousGetPinnableReference(); @@ -181,8 +195,11 @@ namespace ImageSharp.PixelFormats } /// - internal override void ToZyxBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) + internal override void ToZyxBytes(Span sourceColors, Span destBytes, int count) { + Guard.MustBeSizedAtLeast(sourceColors, count, nameof(sourceColors)); + Guard.MustBeSizedAtLeast(destBytes, count * 3, nameof(destBytes)); + ref Rgba32 sourceRef = ref sourceColors.DangerousGetPinnableReference(); ref RGB24 destRef = ref Unsafe.As(ref destBytes.DangerousGetPinnableReference()); @@ -196,8 +213,11 @@ namespace ImageSharp.PixelFormats } /// - internal override void PackFromZyxwBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) + internal override void PackFromZyxwBytes(Span sourceBytes, Span destColors, int count) { + Guard.MustBeSizedAtLeast(sourceBytes, count * 4, nameof(sourceBytes)); + Guard.MustBeSizedAtLeast(destColors, count, nameof(destColors)); + ref RGBA32 sourceRef = ref Unsafe.As(ref sourceBytes.DangerousGetPinnableReference()); ref Rgba32 destRef = ref destColors.DangerousGetPinnableReference(); @@ -211,8 +231,11 @@ namespace ImageSharp.PixelFormats } /// - internal override void ToZyxwBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) + internal override void ToZyxwBytes(Span sourceColors, Span destBytes, int count) { + Guard.MustBeSizedAtLeast(sourceColors, count, nameof(sourceColors)); + Guard.MustBeSizedAtLeast(destBytes, count * 4, nameof(destBytes)); + ref Rgba32 sourceRef = ref sourceColors.DangerousGetPinnableReference(); ref RGBA32 destRef = ref Unsafe.As(ref destBytes.DangerousGetPinnableReference()); diff --git a/src/ImageSharp/PixelFormats/Rgba32.cs b/src/ImageSharp/PixelFormats/Rgba32.cs index f58150e2e..9b82a3701 100644 --- a/src/ImageSharp/PixelFormats/Rgba32.cs +++ b/src/ImageSharp/PixelFormats/Rgba32.cs @@ -3,13 +3,14 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.PixelFormats +namespace ImageSharp { + using System; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; - using ImageSharp.ColorSpaces; + using ImageSharp.PixelFormats; /// /// Packed pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255. @@ -156,30 +157,7 @@ namespace ImageSharp.PixelFormats } /// - public uint PackedValue - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => this.Rgba; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - set => this.Rgba = value; - } - - /// - /// Allows the implicit conversion of an instance of to a - /// . - /// - /// - /// The instance of to convert. - /// - /// - /// An instance of . - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static implicit operator Rgba32(Rgb color) - { - return new Rgba32(color.R, color.G, color.B); - } + public uint PackedValue { get => this.Rgba; set => this.Rgba = value; } /// /// Compares two objects for equality. @@ -229,7 +207,6 @@ namespace ImageSharp.PixelFormats } /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public PixelOperations CreateBulkOperations() => new PixelOperations(); /// @@ -254,7 +231,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzBytes(byte[] bytes, int startIndex) + public void ToXyzBytes(Span bytes, int startIndex) { bytes[startIndex] = this.R; bytes[startIndex + 1] = this.G; @@ -263,7 +240,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzwBytes(byte[] bytes, int startIndex) + public void ToXyzwBytes(Span bytes, int startIndex) { bytes[startIndex] = this.R; bytes[startIndex + 1] = this.G; @@ -273,7 +250,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxBytes(byte[] bytes, int startIndex) + public void ToZyxBytes(Span bytes, int startIndex) { bytes[startIndex] = this.B; bytes[startIndex + 1] = this.G; @@ -282,7 +259,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxwBytes(byte[] bytes, int startIndex) + public void ToZyxwBytes(Span bytes, int startIndex) { bytes[startIndex] = this.B; bytes[startIndex + 1] = this.G; diff --git a/src/ImageSharp/PixelFormats/Rgba64.cs b/src/ImageSharp/PixelFormats/Rgba64.cs index 296c17a4e..417828368 100644 --- a/src/ImageSharp/PixelFormats/Rgba64.cs +++ b/src/ImageSharp/PixelFormats/Rgba64.cs @@ -107,7 +107,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzBytes(byte[] bytes, int startIndex) + public void ToXyzBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; @@ -118,7 +118,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzwBytes(byte[] bytes, int startIndex) + public void ToXyzwBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; @@ -130,7 +130,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxBytes(byte[] bytes, int startIndex) + public void ToZyxBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; @@ -141,7 +141,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxwBytes(byte[] bytes, int startIndex) + public void ToZyxwBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; diff --git a/src/ImageSharp/PixelFormats/RgbaVector.PixelOperations.cs b/src/ImageSharp/PixelFormats/RgbaVector.PixelOperations.cs index da0900c11..ac25b7f14 100644 --- a/src/ImageSharp/PixelFormats/RgbaVector.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/RgbaVector.PixelOperations.cs @@ -5,8 +5,11 @@ namespace ImageSharp.PixelFormats { + using System; using System.Numerics; + using ImageSharp.Memory; + /// /// Provides optimized overrides for bulk operations. /// @@ -18,9 +21,12 @@ namespace ImageSharp.PixelFormats internal class PixelOperations : PixelOperations { /// - internal override unsafe void ToVector4(BufferSpan sourceColors, BufferSpan destVectors, int count) + internal override unsafe void ToVector4(Span sourceColors, Span destVectors, int count) { - BufferSpan.Copy(sourceColors.AsBytes(), destVectors.AsBytes(), count * sizeof(Vector4)); + Guard.MustBeSizedAtLeast(sourceColors, count, nameof(sourceColors)); + Guard.MustBeSizedAtLeast(destVectors, count, nameof(destVectors)); + + SpanHelper.Copy(sourceColors.AsBytes(), destVectors.AsBytes(), count * sizeof(Vector4)); } } } diff --git a/src/ImageSharp/PixelFormats/RgbaVector.cs b/src/ImageSharp/PixelFormats/RgbaVector.cs index a92b794ef..5332f4a8e 100644 --- a/src/ImageSharp/PixelFormats/RgbaVector.cs +++ b/src/ImageSharp/PixelFormats/RgbaVector.cs @@ -5,6 +5,7 @@ namespace ImageSharp.PixelFormats { + using System; using System.Numerics; using System.Runtime.CompilerServices; @@ -234,7 +235,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzBytes(byte[] bytes, int startIndex) + public void ToXyzBytes(Span bytes, int startIndex) { Vector4 vector = Vector4.Clamp(this.backingVector, Vector4.Zero, Vector4.One) * MaxBytes; vector += Half; @@ -245,7 +246,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzwBytes(byte[] bytes, int startIndex) + public void ToXyzwBytes(Span bytes, int startIndex) { Vector4 vector = Vector4.Clamp(this.backingVector, Vector4.Zero, Vector4.One) * MaxBytes; vector += Half; @@ -257,7 +258,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxBytes(byte[] bytes, int startIndex) + public void ToZyxBytes(Span bytes, int startIndex) { Vector4 vector = Vector4.Clamp(this.backingVector, Vector4.Zero, Vector4.One) * MaxBytes; vector += Half; @@ -268,7 +269,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxwBytes(byte[] bytes, int startIndex) + public void ToZyxwBytes(Span bytes, int startIndex) { Vector4 vector = Vector4.Clamp(this.backingVector, Vector4.Zero, Vector4.One) * MaxBytes; vector += Half; diff --git a/src/ImageSharp/PixelFormats/Short2.cs b/src/ImageSharp/PixelFormats/Short2.cs index 6c871ecb6..b848b5505 100644 --- a/src/ImageSharp/PixelFormats/Short2.cs +++ b/src/ImageSharp/PixelFormats/Short2.cs @@ -119,7 +119,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzBytes(byte[] bytes, int startIndex) + public void ToXyzBytes(Span bytes, int startIndex) { Vector2 vector = this.ToVector2(); vector /= 65534; @@ -135,7 +135,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzwBytes(byte[] bytes, int startIndex) + public void ToXyzwBytes(Span bytes, int startIndex) { Vector2 vector = this.ToVector2(); vector /= 65534; @@ -152,7 +152,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxBytes(byte[] bytes, int startIndex) + public void ToZyxBytes(Span bytes, int startIndex) { Vector2 vector = this.ToVector2(); vector /= 65534; @@ -168,7 +168,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxwBytes(byte[] bytes, int startIndex) + public void ToZyxwBytes(Span bytes, int startIndex) { Vector2 vector = this.ToVector2(); vector /= 65534; diff --git a/src/ImageSharp/PixelFormats/Short4.cs b/src/ImageSharp/PixelFormats/Short4.cs index de110c7d3..763de19bc 100644 --- a/src/ImageSharp/PixelFormats/Short4.cs +++ b/src/ImageSharp/PixelFormats/Short4.cs @@ -125,7 +125,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzBytes(byte[] bytes, int startIndex) + public void ToXyzBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4(); vector /= 65534; @@ -141,7 +141,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzwBytes(byte[] bytes, int startIndex) + public void ToXyzwBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4(); vector /= 65534; @@ -158,7 +158,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxBytes(byte[] bytes, int startIndex) + public void ToZyxBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4(); vector /= 65534; @@ -174,7 +174,7 @@ namespace ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxwBytes(byte[] bytes, int startIndex) + public void ToZyxwBytes(Span bytes, int startIndex) { Vector4 vector = this.ToVector4(); vector /= 65534; diff --git a/src/ImageSharp/Processing/Binarization/Dither.cs b/src/ImageSharp/Processing/Binarization/Dither.cs index 617883d6a..2a359c089 100644 --- a/src/ImageSharp/Processing/Binarization/Dither.cs +++ b/src/ImageSharp/Processing/Binarization/Dither.cs @@ -12,7 +12,7 @@ namespace ImageSharp using ImageSharp.Processing.Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -40,7 +40,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The component index to test the threshold against. Must range from 0 to 3. - /// The . + /// The . public static Image Dither(this Image source, IOrderedDither dither, Rectangle rectangle, int index = 0) where TPixel : struct, IPixel { @@ -72,7 +72,7 @@ namespace ImageSharp /// /// The structure that specifies the portion of the image object to alter. /// - /// The . + /// The . public static Image Dither(this Image source, IErrorDiffuser diffuser, float threshold, Rectangle rectangle) where TPixel : struct, IPixel { diff --git a/src/ImageSharp/Processing/ColorMatrix/Sepia.cs b/src/ImageSharp/Processing/ColorMatrix/Sepia.cs index d60ec7165..39eca4e8e 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Sepia.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Sepia.cs @@ -22,7 +22,7 @@ namespace ImageSharp /// /// The pixel format. /// The image this method extends. - /// The . + /// The . public static Image Sepia(this Image source) where TPixel : struct, IPixel { @@ -37,7 +37,7 @@ namespace ImageSharp /// /// The structure that specifies the portion of the image object to alter. /// - /// The . + /// The . public static Image Sepia(this Image source, Rectangle rectangle) where TPixel : struct, IPixel { diff --git a/src/ImageSharp/Processing/Effects/Alpha.cs b/src/ImageSharp/Processing/Effects/Alpha.cs index a2f721cfa..73b682b93 100644 --- a/src/ImageSharp/Processing/Effects/Alpha.cs +++ b/src/ImageSharp/Processing/Effects/Alpha.cs @@ -12,7 +12,7 @@ namespace ImageSharp using Processing.Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -38,7 +38,7 @@ namespace ImageSharp /// /// The structure that specifies the portion of the image object to alter. /// - /// The . + /// The . public static Image Alpha(this Image source, float percent, Rectangle rectangle) where TPixel : struct, IPixel { diff --git a/src/ImageSharp/Processing/Effects/BackgroundColor.cs b/src/ImageSharp/Processing/Effects/BackgroundColor.cs index f52cf1cb2..975d2c24b 100644 --- a/src/ImageSharp/Processing/Effects/BackgroundColor.cs +++ b/src/ImageSharp/Processing/Effects/BackgroundColor.cs @@ -40,7 +40,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The options effecting pixel blending. - /// The . + /// The . public static Image BackgroundColor(this Image source, TPixel color, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel { @@ -70,7 +70,7 @@ namespace ImageSharp /// /// The structure that specifies the portion of the image object to alter. /// - /// The . + /// The . public static Image BackgroundColor(this Image source, TPixel color, Rectangle rectangle) where TPixel : struct, IPixel { diff --git a/src/ImageSharp/Processing/Effects/Invert.cs b/src/ImageSharp/Processing/Effects/Invert.cs index 113d8289e..fe3bb7dc9 100644 --- a/src/ImageSharp/Processing/Effects/Invert.cs +++ b/src/ImageSharp/Processing/Effects/Invert.cs @@ -21,7 +21,7 @@ namespace ImageSharp /// /// The pixel format. /// The image this method extends. - /// The . + /// The . public static Image Invert(this Image source) where TPixel : struct, IPixel { @@ -36,7 +36,7 @@ namespace ImageSharp /// /// The structure that specifies the portion of the image object to alter. /// - /// The . + /// The . public static Image Invert(this Image source, Rectangle rectangle) where TPixel : struct, IPixel { diff --git a/src/ImageSharp/ImageProcessor.cs b/src/ImageSharp/Processing/ImageProcessor.cs similarity index 98% rename from src/ImageSharp/ImageProcessor.cs rename to src/ImageSharp/Processing/ImageProcessor.cs index 745b25fb6..d42650e56 100644 --- a/src/ImageSharp/ImageProcessor.cs +++ b/src/ImageSharp/Processing/ImageProcessor.cs @@ -39,11 +39,13 @@ namespace ImageSharp.Processing this.AfterApply(source, sourceRectangle); } - catch (Exception ex) - { #if DEBUG + catch (Exception) + { throw; #else + catch (Exception ex) + { throw new ImageProcessingException($"An error occured when processing the image using {this.GetType().Name}. See the inner exception for more detail.", ex); #endif } diff --git a/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs b/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs index 566449b27..5cd67f053 100644 --- a/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs @@ -12,7 +12,7 @@ namespace ImageSharp.Processing.Processors /// /// An to perform binary threshold filtering against an - /// . The image will be converted to grayscale before thresholding occurs. + /// . The image will be converted to grayscale before thresholding occurs. /// /// The pixel format. internal class BinaryThresholdProcessor : ImageProcessor diff --git a/src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs index 652442388..b97e07079 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs @@ -7,6 +7,7 @@ namespace ImageSharp.Processing.Processors { using System; + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor.cs index e6a42cc0c..29086b53f 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor.cs @@ -8,6 +8,7 @@ namespace ImageSharp.Processing.Processors using System.Numerics; using System.Threading.Tasks; + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor.cs index 965a725a1..e39104793 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor.cs @@ -9,6 +9,7 @@ namespace ImageSharp.Processing.Processors using System.Numerics; using System.Threading.Tasks; + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor.cs index 475f14ccf..17d5e3243 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor.cs @@ -9,6 +9,7 @@ namespace ImageSharp.Processing.Processors using System.Numerics; using System.Threading.Tasks; + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetector2DProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetector2DProcessor.cs index 457854a31..6f1057e00 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetector2DProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetector2DProcessor.cs @@ -7,6 +7,7 @@ namespace ImageSharp.Processing.Processors { using System; + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs index a4d1d5409..a03d12677 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs @@ -9,6 +9,7 @@ namespace ImageSharp.Processing.Processors using System.Numerics; using System.Threading.Tasks; + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorProcessor.cs index e7670dd1d..415b574b8 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorProcessor.cs @@ -7,6 +7,7 @@ namespace ImageSharp.Processing.Processors { using System; + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs index d72816a76..b1361b514 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs @@ -8,6 +8,7 @@ namespace ImageSharp.Processing.Processors using System; using System.Diagnostics.CodeAnalysis; + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/KirschProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/KirschProcessor.cs index d882bdb16..af4700bb9 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/KirschProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/KirschProcessor.cs @@ -8,6 +8,7 @@ namespace ImageSharp.Processing.Processors using System; using System.Diagnostics.CodeAnalysis; + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs index 39f64fb5a..5f58d56f8 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs @@ -8,6 +8,7 @@ namespace ImageSharp.Processing.Processors using System; using System.Diagnostics.CodeAnalysis; + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs index c65cb5bd7..2e365374c 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs @@ -8,6 +8,7 @@ namespace ImageSharp.Processing.Processors using System; using System.Diagnostics.CodeAnalysis; + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs index 57ab4dce6..de2594653 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs @@ -8,6 +8,7 @@ namespace ImageSharp.Processing.Processors using System; using System.Diagnostics.CodeAnalysis; + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/PrewittProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/PrewittProcessor.cs index d1515dee8..1b2d5f50e 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/PrewittProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/PrewittProcessor.cs @@ -8,6 +8,7 @@ namespace ImageSharp.Processing.Processors using System; using System.Diagnostics.CodeAnalysis; + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs index bab9ff622..d1b9614b6 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs @@ -8,6 +8,7 @@ namespace ImageSharp.Processing.Processors using System; using System.Diagnostics.CodeAnalysis; + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs index 4afca0f01..bc687f674 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs @@ -8,6 +8,7 @@ namespace ImageSharp.Processing.Processors using System; using System.Diagnostics.CodeAnalysis; + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/ScharrProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/ScharrProcessor.cs index a583d3c0d..339b9741f 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/ScharrProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/ScharrProcessor.cs @@ -8,6 +8,7 @@ namespace ImageSharp.Processing.Processors using System; using System.Diagnostics.CodeAnalysis; + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/SobelProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/SobelProcessor.cs index 1c2a6a18f..b9060ecbc 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/SobelProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/SobelProcessor.cs @@ -8,6 +8,7 @@ namespace ImageSharp.Processing.Processors using System; using System.Diagnostics.CodeAnalysis; + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs index 87de922a1..4cd49e149 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs @@ -7,6 +7,7 @@ namespace ImageSharp.Processing.Processors { using System; + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs index 34d099033..5bb29a67e 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs @@ -7,6 +7,7 @@ namespace ImageSharp.Processing.Processors { using System; + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// diff --git a/src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs index 511a810b2..cc95f15fc 100644 --- a/src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs @@ -9,6 +9,7 @@ namespace ImageSharp.Processing.Processors using System.Numerics; using System.Threading.Tasks; + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// @@ -82,7 +83,7 @@ namespace ImageSharp.Processing.Processors { int offsetY = y - startY; - BufferSpan destination = sourcePixels.GetRowSpan(offsetY).Slice(minX - startX, width); + Span destination = sourcePixels.GetRowSpan(offsetY).Slice(minX - startX, width); // this switched color & destination in the 2nd and 3rd places because we are applying the target colour under the current one blender.Blend(destination, colors, destination, amount); diff --git a/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs b/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs index 5b5d64a9c..9de91c47b 100644 --- a/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs @@ -9,6 +9,7 @@ namespace ImageSharp.Processing.Processors using System.Numerics; using System.Threading.Tasks; + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// @@ -96,7 +97,7 @@ namespace ImageSharp.Processing.Processors amounts[i] = (this.options.BlendPercentage * (1 - (.95F * (distance / maxDistance)))).Clamp(0, 1); } - BufferSpan destination = sourcePixels.GetRowSpan(offsetY).Slice(offsetX, width); + Span destination = sourcePixels.GetRowSpan(offsetY).Slice(offsetX, width); this.blender.Blend(destination, destination, rowColors, amounts); } diff --git a/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs b/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs index d698b543c..be431b07d 100644 --- a/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs @@ -9,6 +9,7 @@ namespace ImageSharp.Processing.Processors using System.Numerics; using System.Threading.Tasks; + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// @@ -104,7 +105,7 @@ namespace ImageSharp.Processing.Processors amounts[i] = (this.options.BlendPercentage * (.9F * (distance / maxDistance))).Clamp(0, 1); } - BufferSpan destination = sourcePixels.GetRowSpan(offsetY).Slice(offsetX, width); + Span destination = sourcePixels.GetRowSpan(offsetY).Slice(offsetX, width); this.blender.Blend(destination, destination, rowColors, amounts); } diff --git a/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.Weights.cs b/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.Weights.cs index f9c78c12f..d49f37803 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.Weights.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.Weights.cs @@ -4,6 +4,8 @@ namespace ImageSharp.Processing.Processors using System.Numerics; using System.Runtime.CompilerServices; + using ImageSharp.Memory; + /// /// Conains the definition of and . /// @@ -12,7 +14,7 @@ namespace ImageSharp.Processing.Processors /// /// Points to a collection of of weights allocated in . /// - internal unsafe struct WeightsWindow + internal struct WeightsWindow { /// /// The local left index position @@ -22,9 +24,7 @@ namespace ImageSharp.Processing.Processors /// /// The span of weights pointing to . /// - // TODO: In the case of switching to official System.Memory and System.Buffers.Primitives this should be System.Buffers.Buffer (formerly Memory), because Span is stack-only! - // see: https://github.com/dotnet/corefxlab/blob/873d35ebed7264e2f9adb556f3b61bebc12395d6/docs/specs/memory.md - public BufferSpan Span; + public Span Span; /// /// Initializes a new instance of the struct. @@ -32,7 +32,7 @@ namespace ImageSharp.Processing.Processors /// The local left index /// The span [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal WeightsWindow(int left, BufferSpan span) + internal WeightsWindow(int left, Span span) { this.Left = left; this.Span = span; @@ -55,7 +55,7 @@ namespace ImageSharp.Processing.Processors /// The source row position. /// The weighted sum [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Vector4 ComputeWeightedRowSum(BufferSpan rowSpan, int sourceX) + public Vector4 ComputeWeightedRowSum(Span rowSpan, int sourceX) { ref float horizontalValues = ref this.Ptr; int left = this.Left; @@ -82,7 +82,7 @@ namespace ImageSharp.Processing.Processors /// The source row position. /// The weighted sum [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Vector4 ComputeExpandedWeightedRowSum(BufferSpan rowSpan, int sourceX) + public Vector4 ComputeExpandedWeightedRowSum(Span rowSpan, int sourceX) { ref float horizontalValues = ref this.Ptr; int left = this.Left; @@ -169,7 +169,7 @@ namespace ImageSharp.Processing.Processors /// The weights public WeightsWindow GetWeightsWindow(int destIdx, int leftIdx, int rightIdx) { - BufferSpan span = this.dataBuffer.GetRowSpan(destIdx).Slice(leftIdx, rightIdx - leftIdx + 1); + Span span = this.dataBuffer.GetRowSpan(destIdx).Slice(leftIdx, rightIdx - leftIdx + 1); return new WeightsWindow(leftIdx, span); } } diff --git a/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs index dde79a7e4..61a64f60f 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs @@ -9,6 +9,7 @@ namespace ImageSharp.Processing.Processors using System.Numerics; using System.Threading.Tasks; + using ImageSharp.Memory; using ImageSharp.PixelFormats; /// @@ -121,7 +122,7 @@ 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); + Span sourceRow = sourcePixels.GetRowSpan(y); PixelOperations.Instance.ToVector4( sourceRow, diff --git a/src/ImageSharp/Processing/Transforms/AutoOrient.cs b/src/ImageSharp/Processing/Transforms/AutoOrient.cs index de736092d..f9d3a60aa 100644 --- a/src/ImageSharp/Processing/Transforms/AutoOrient.cs +++ b/src/ImageSharp/Processing/Transforms/AutoOrient.cs @@ -22,7 +22,7 @@ namespace ImageSharp /// /// The pixel format. /// The image to auto rotate. - /// The + /// The public static Image AutoOrient(this Image source) where TPixel : struct, IPixel { diff --git a/src/ImageSharp/Processing/Transforms/Crop.cs b/src/ImageSharp/Processing/Transforms/Crop.cs index 073e8136d..1cdef56c4 100644 --- a/src/ImageSharp/Processing/Transforms/Crop.cs +++ b/src/ImageSharp/Processing/Transforms/Crop.cs @@ -38,7 +38,7 @@ namespace ImageSharp /// /// The structure that specifies the portion of the image object to retain. /// - /// The + /// The public static Image Crop(this Image source, Rectangle cropRectangle) where TPixel : struct, IPixel { diff --git a/src/ImageSharp/Processing/Transforms/EntropyCrop.cs b/src/ImageSharp/Processing/Transforms/EntropyCrop.cs index aaafd396f..2f4a8e383 100644 --- a/src/ImageSharp/Processing/Transforms/EntropyCrop.cs +++ b/src/ImageSharp/Processing/Transforms/EntropyCrop.cs @@ -22,7 +22,7 @@ namespace ImageSharp /// The pixel format. /// The image to crop. /// The threshold for entropic density. - /// The + /// The public static Image EntropyCrop(this Image source, float threshold = .5f) where TPixel : struct, IPixel { diff --git a/src/ImageSharp/Processing/Transforms/Flip.cs b/src/ImageSharp/Processing/Transforms/Flip.cs index 41f2e5616..342b4dd46 100644 --- a/src/ImageSharp/Processing/Transforms/Flip.cs +++ b/src/ImageSharp/Processing/Transforms/Flip.cs @@ -23,7 +23,7 @@ namespace ImageSharp /// The pixel format. /// The image to rotate, flip, or both. /// The to perform the flip. - /// The + /// The public static Image Flip(this Image source, FlipType flipType) where TPixel : struct, IPixel { diff --git a/src/ImageSharp/Processing/Transforms/Rotate.cs b/src/ImageSharp/Processing/Transforms/Rotate.cs index b335a3c76..de9dbdc3b 100644 --- a/src/ImageSharp/Processing/Transforms/Rotate.cs +++ b/src/ImageSharp/Processing/Transforms/Rotate.cs @@ -23,7 +23,7 @@ namespace ImageSharp /// The pixel format. /// The image to rotate. /// The angle in degrees to perform the rotation. - /// The + /// The public static Image Rotate(this Image source, float degrees) where TPixel : struct, IPixel { @@ -36,7 +36,7 @@ namespace ImageSharp /// The pixel format. /// The image to rotate. /// The to perform the rotation. - /// The + /// The public static Image Rotate(this Image source, RotateType rotateType) where TPixel : struct, IPixel { @@ -50,7 +50,7 @@ namespace ImageSharp /// The image to rotate. /// The angle in degrees to perform the rotation. /// Whether to expand the image to fit the rotated result. - /// The + /// The public static Image Rotate(this Image source, float degrees, bool expand) where TPixel : struct, IPixel { diff --git a/src/ImageSharp/Processing/Transforms/RotateFlip.cs b/src/ImageSharp/Processing/Transforms/RotateFlip.cs index 396590359..460d004cb 100644 --- a/src/ImageSharp/Processing/Transforms/RotateFlip.cs +++ b/src/ImageSharp/Processing/Transforms/RotateFlip.cs @@ -23,7 +23,7 @@ namespace ImageSharp /// The image to rotate, flip, or both. /// The to perform the rotation. /// The to perform the flip. - /// The + /// The public static Image RotateFlip(this Image source, RotateType rotateType, FlipType flipType) where TPixel : struct, IPixel { diff --git a/src/ImageSharp/Processing/Transforms/Skew.cs b/src/ImageSharp/Processing/Transforms/Skew.cs index 0c9cfbc8e..d42d79225 100644 --- a/src/ImageSharp/Processing/Transforms/Skew.cs +++ b/src/ImageSharp/Processing/Transforms/Skew.cs @@ -23,7 +23,7 @@ namespace ImageSharp /// 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 + /// The public static Image Skew(this Image source, float degreesX, float degreesY) where TPixel : struct, IPixel { @@ -38,7 +38,7 @@ namespace ImageSharp /// 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 + /// The public static Image Skew(this Image source, float degreesX, float degreesY, bool expand) where TPixel : struct, IPixel { diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4ReferenceVsPointer.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4ReferenceVsPointer.cs index 65c4a235d..30d93e3d9 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4ReferenceVsPointer.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4ReferenceVsPointer.cs @@ -6,7 +6,7 @@ using BenchmarkDotNet.Attributes; using ImageSharp; - using ImageSharp.PixelFormats; + using ImageSharp.Memory; /// /// Compares two implementation candidates for general BulkPixelOperations.ToVector4(): diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs index efec90c99..501ae7949 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs @@ -3,6 +3,7 @@ namespace ImageSharp.Benchmarks.Color.Bulk { using BenchmarkDotNet.Attributes; + using ImageSharp.Memory; using ImageSharp.PixelFormats; public abstract class PackFromXyzw @@ -57,7 +58,7 @@ namespace ImageSharp.Benchmarks.Color.Bulk } } - public class PackFromXyzw_Color : PackFromXyzw + public class PackFromXyzw_Rgba32 : 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 e2c1ac726..65a2988b9 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs @@ -5,6 +5,7 @@ namespace ImageSharp.Benchmarks.Color.Bulk using BenchmarkDotNet.Attributes; + using ImageSharp.Memory; using ImageSharp.PixelFormats; public abstract class ToVector4 @@ -57,7 +58,7 @@ namespace ImageSharp.Benchmarks.Color.Bulk } } - public class ToVector4_Color : ToVector4 + public class ToVector4_Rgba32 : 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 88dac21cd..3c75fc2d1 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs @@ -3,6 +3,7 @@ namespace ImageSharp.Benchmarks.Color.Bulk { using BenchmarkDotNet.Attributes; + using ImageSharp.Memory; using ImageSharp.PixelFormats; public abstract class ToXyz @@ -55,7 +56,7 @@ namespace ImageSharp.Benchmarks.Color.Bulk } } - public class ToXyz_Color : ToXyz + public class ToXyz_Rgba32 : 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 11545d3d9..f64bf561b 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs @@ -7,6 +7,8 @@ using System.Threading.Tasks; namespace ImageSharp.Benchmarks.Color.Bulk { using BenchmarkDotNet.Attributes; + + using ImageSharp.Memory; using ImageSharp.PixelFormats; public abstract class ToXyzw @@ -58,12 +60,12 @@ namespace ImageSharp.Benchmarks.Color.Bulk PixelOperations.Instance.ToXyzwBytes(this.source, this.destination, this.Count); } } - - public class ToXyzw_Color : ToXyzw + + public class ToXyzw_Rgba32 : ToXyzw { } - public class ToXyzw_Argb : ToXyzw + public class ToXyzw_Argb32 : ToXyzw { } } diff --git a/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs b/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs index d0bd9f208..183782d91 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs @@ -14,9 +14,6 @@ namespace ImageSharp.Benchmarks using ImageSharp.PixelFormats; - using CoreImage = ImageSharp.Image; - using CorePoint = ImageSharp.Point; - public class DrawBeziers : BenchmarkBase { [Benchmark(Baseline = true, Description = "System.Drawing Draw Beziers")] @@ -48,7 +45,7 @@ namespace ImageSharp.Benchmarks [Benchmark(Description = "ImageSharp Draw Beziers")] public void DrawLinesCore() { - using (CoreImage image = new CoreImage(800, 800)) + using (Image image = new Image(800, 800)) { image.DrawBeziers( Rgba32.HotPink, diff --git a/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs b/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs index 2bd3f4a6a..5ecdec2c2 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs @@ -14,9 +14,6 @@ namespace ImageSharp.Benchmarks using ImageSharp.PixelFormats; - using CoreImage = ImageSharp.Image; - using CorePoint = ImageSharp.Point; - public class DrawLines : BenchmarkBase { [Benchmark(Baseline = true, Description = "System.Drawing Draw Lines")] @@ -24,7 +21,6 @@ namespace ImageSharp.Benchmarks { using (Bitmap destination = new Bitmap(800, 800)) { - using (Graphics graphics = Graphics.FromImage(destination)) { graphics.InterpolationMode = InterpolationMode.Default; @@ -47,7 +43,7 @@ namespace ImageSharp.Benchmarks [Benchmark(Description = "ImageSharp Draw Lines")] public void DrawLinesCore() { - using (CoreImage image = new CoreImage(800, 800)) + using (Image image = new Image(800, 800)) { image.DrawLines( Rgba32.HotPink, diff --git a/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs b/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs index a0f8b21d8..d3ff33956 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs @@ -9,8 +9,7 @@ namespace ImageSharp.Benchmarks using System.Drawing.Drawing2D; using BenchmarkDotNet.Attributes; - using CoreImage = ImageSharp.Image; - using CorePoint = ImageSharp.Point; + using System.IO; using System.Numerics; @@ -46,7 +45,7 @@ namespace ImageSharp.Benchmarks [Benchmark(Description = "ImageSharp Draw Polygon")] public void DrawPolygonCore() { - using (CoreImage image = new CoreImage(800, 800)) + using (Image image = new Image(800, 800)) { image.DrawPolygon( Rgba32.HotPink, diff --git a/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs b/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs index ac1082697..deba59554 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs @@ -15,8 +15,6 @@ namespace ImageSharp.Benchmarks using ImageSharp.PixelFormats; - using CoreImage = ImageSharp.Image; - public class FillPolygon : BenchmarkBase { private readonly Polygon shape; @@ -55,7 +53,7 @@ namespace ImageSharp.Benchmarks [Benchmark(Description = "ImageSharp Fill Polygon")] public void DrawSolidPolygonCore() { - using (CoreImage image = new CoreImage(800, 800)) + using (Image image = new Image(800, 800)) { image.FillPolygon( Rgba32.HotPink, @@ -75,7 +73,7 @@ namespace ImageSharp.Benchmarks [Benchmark(Description = "ImageSharp Fill Polygon - cached shape")] public void DrawSolidPolygonCoreCahced() { - using (CoreImage image = new CoreImage(800, 800)) + using (Image image = new Image(800, 800)) { image.Fill( Rgba32.HotPink, diff --git a/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs b/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs index 7b21dbdc6..a90a7a4c0 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs @@ -9,7 +9,6 @@ namespace ImageSharp.Benchmarks using System.Drawing.Drawing2D; using BenchmarkDotNet.Attributes; - using CoreImage = ImageSharp.Image; using CoreRectangle = ImageSharp.Rectangle; using CoreSize = ImageSharp.Size; @@ -38,7 +37,7 @@ namespace ImageSharp.Benchmarks [Benchmark(Description = "ImageSharp Fill Rectangle")] public CoreSize FillRactangleCore() { - using (CoreImage image = new CoreImage(800, 800)) + using (Image image = new Image(800, 800)) { image.Fill(Rgba32.HotPink, new CoreRectangle(10, 10, 190, 140)); @@ -49,7 +48,7 @@ namespace ImageSharp.Benchmarks [Benchmark(Description = "ImageSharp Fill Rectangle - As Polygon")] public CoreSize FillPolygonCore() { - using (CoreImage image = new CoreImage(800, 800)) + using (Image image = new Image(800, 800)) { image.FillPolygon( Rgba32.HotPink, diff --git a/tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs b/tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs index 580120abd..aa97efe00 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs @@ -11,11 +11,9 @@ namespace ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; - using ImageSharp.PixelFormats; - + using ImageSharp.Drawing.Brushes; using CoreBrushes = ImageSharp.Drawing.Brushes.Brushes; - - using CoreImage = ImageSharp.Image; + using ImageSharp.PixelFormats; public class FillWithPattern { @@ -40,7 +38,7 @@ namespace ImageSharp.Benchmarks [Benchmark(Description = "ImageSharp Fill with Pattern")] public void DrawPatternPolygon3Core() { - using (CoreImage image = new CoreImage(800, 800)) + using (Image image = new Image(800, 800)) { image.Fill(CoreBrushes.BackwardDiagonal(Rgba32.HotPink)); diff --git a/tests/ImageSharp.Benchmarks/General/Array2D.cs b/tests/ImageSharp.Benchmarks/General/Array2D.cs index fce92e9be..9d44fc93d 100644 --- a/tests/ImageSharp.Benchmarks/General/Array2D.cs +++ b/tests/ImageSharp.Benchmarks/General/Array2D.cs @@ -9,6 +9,8 @@ namespace ImageSharp.Benchmarks.General using BenchmarkDotNet.Attributes; + using ImageSharp.Memory; + public class Array2D { private float[] flatArray; diff --git a/tests/ImageSharp.Benchmarks/General/ClearBuffer.cs b/tests/ImageSharp.Benchmarks/General/ClearBuffer.cs index 97deb72c5..fc1b46a91 100644 --- a/tests/ImageSharp.Benchmarks/General/ClearBuffer.cs +++ b/tests/ImageSharp.Benchmarks/General/ClearBuffer.cs @@ -3,11 +3,10 @@ namespace ImageSharp.Benchmarks.General { using System; using System.Runtime.CompilerServices; - using System.Runtime.InteropServices; using BenchmarkDotNet.Attributes; - using ImageSharp.PixelFormats; + using ImageSharp.Memory; public unsafe class ClearBuffer { diff --git a/tests/ImageSharp.Benchmarks/General/IterateArray.cs b/tests/ImageSharp.Benchmarks/General/IterateArray.cs index eeab6506a..b9e2f7acd 100644 --- a/tests/ImageSharp.Benchmarks/General/IterateArray.cs +++ b/tests/ImageSharp.Benchmarks/General/IterateArray.cs @@ -5,6 +5,8 @@ namespace ImageSharp.Benchmarks.General using BenchmarkDotNet.Attributes; + using ImageSharp.Memory; + public class IterateArray { // Usual pinned stuff diff --git a/tests/ImageSharp.Benchmarks/General/PixelIndexing.cs b/tests/ImageSharp.Benchmarks/General/PixelIndexing.cs index d9237b801..18c99a744 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelIndexing.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelIndexing.cs @@ -5,6 +5,8 @@ using BenchmarkDotNet.Attributes; + using ImageSharp.Memory; + // Pixel indexing benchmarks compare different methods for getting/setting all pixel values in a subsegment of a single pixel row. public abstract unsafe class PixelIndexing { diff --git a/tests/ImageSharp.Benchmarks/General/Vectorization/MulFloat.cs b/tests/ImageSharp.Benchmarks/General/Vectorization/MulFloat.cs index 151145e12..ee33cf210 100644 --- a/tests/ImageSharp.Benchmarks/General/Vectorization/MulFloat.cs +++ b/tests/ImageSharp.Benchmarks/General/Vectorization/MulFloat.cs @@ -24,7 +24,7 @@ namespace ImageSharp.Benchmarks.General.Vectorization for (int i = 0; i < this.InputSize; i++) { - this.input[i] = (uint)i; + this.input[i] = i; } } @@ -39,7 +39,7 @@ namespace ImageSharp.Benchmarks.General.Vectorization } [Benchmark] - public void Simd() + public void SimdMultiplyByVector() { Vector v = new Vector(this.testValue); @@ -50,5 +50,18 @@ namespace ImageSharp.Benchmarks.General.Vectorization a.CopyTo(this.result, i); } } + + [Benchmark] + public void SimdMultiplyByScalar() + { + float v = this.testValue; + + for (int i = 0; i < this.input.Length; i += Vector.Count) + { + Vector a = new Vector(this.input, i); + a = a * v; + a.CopyTo(this.result, i); + } + } } } \ No newline at end of file diff --git a/tests/ImageSharp.Benchmarks/General/Vectorization/VectorFetching.cs b/tests/ImageSharp.Benchmarks/General/Vectorization/VectorFetching.cs new file mode 100644 index 000000000..018f11334 --- /dev/null +++ b/tests/ImageSharp.Benchmarks/General/Vectorization/VectorFetching.cs @@ -0,0 +1,110 @@ +namespace ImageSharp.Benchmarks.General.Vectorization +{ + using System; + using System.Numerics; + using System.Runtime.CompilerServices; + + using BenchmarkDotNet.Attributes; + using ImageSharp.Memory; + + /// + /// This benchmark compares different methods for fetching memory data into + /// checking if JIT has limitations. Normally SIMD acceleration should be here for all methods. + /// + public class VectorFetching + { + private float testValue; + + private float[] data; + + [Params(64)] + public int InputSize { get; set; } + + [Setup] + public void Setup() + { + this.data = new float[this.InputSize]; + this.testValue = 42; + + for (int i = 0; i < this.InputSize; i++) + { + this.data[i] = i; + } + } + + [Benchmark(Baseline = true)] + public void Baseline() + { + float v = this.testValue; + for (int i = 0; i < this.data.Length; i++) + { + this.data[i] = this.data[i] * v; + } + } + + [Benchmark] + public void FetchWithVectorConstructor() + { + Vector v = new Vector(this.testValue); + + for (int i = 0; i < this.data.Length; i += Vector.Count) + { + Vector a = new Vector(this.data, i); + a = a * v; + a.CopyTo(this.data, i); + } + } + + [Benchmark] + public void FetchWithUnsafeCast() + { + Vector v = new Vector(this.testValue); + ref Vector start = ref Unsafe.As>(ref this.data[0]); + + int n = this.InputSize / Vector.Count; + + for (int i = 0; i < n; i++) + { + ref Vector p = ref Unsafe.Add(ref start, i); + + Vector a = p; + a = a * v; + + p = a; + } + } + + [Benchmark] + public void FetchWithUnsafeCastNoTempVector() + { + Vector v = new Vector(this.testValue); + ref Vector start = ref Unsafe.As>(ref this.data[0]); + + int n = this.InputSize / Vector.Count; + + for (int i = 0; i < n; i++) + { + ref Vector a = ref Unsafe.Add(ref start, i); + a = a * v; + } + } + + [Benchmark] + public void FetchWithSpanUtility() + { + Vector v = new Vector(this.testValue); + + Span span = new Span(this.data); + + ref Vector start = ref span.FetchVector(); + + int n = this.InputSize / Vector.Count; + + for (int i = 0; i < n; i++) + { + ref Vector a = ref Unsafe.Add(ref start, i); + a = a * v; + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs b/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs index aade8a8de..5b5d14750 100644 --- a/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs +++ b/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs @@ -11,15 +11,13 @@ namespace ImageSharp.Benchmarks.Image using ImageSharp.PixelFormats; - using CoreImage = ImageSharp.Image; - public class CopyPixels : BenchmarkBase { [Benchmark(Description = "Copy by Pixel")] public Rgba32 CopyByPixel() { - using (CoreImage source = new CoreImage(1024, 768)) - using (CoreImage target = new CoreImage(1024, 768)) + using (Image source = new Image(1024, 768)) + using (Image target = new Image(1024, 768)) { using (PixelAccessor sourcePixels = source.Lock()) using (PixelAccessor targetPixels = target.Lock()) diff --git a/tests/ImageSharp.Benchmarks/Image/DecodeBmp.cs b/tests/ImageSharp.Benchmarks/Image/DecodeBmp.cs index acde8e0db..87baa8b7e 100644 --- a/tests/ImageSharp.Benchmarks/Image/DecodeBmp.cs +++ b/tests/ImageSharp.Benchmarks/Image/DecodeBmp.cs @@ -11,6 +11,7 @@ namespace ImageSharp.Benchmarks.Image using BenchmarkDotNet.Attributes; using CoreImage = ImageSharp.Image; + using CoreSize = ImageSharp.Size; public class DecodeBmp : BenchmarkBase @@ -43,7 +44,7 @@ namespace ImageSharp.Benchmarks.Image { using (MemoryStream memoryStream = new MemoryStream(this.bmpBytes)) { - using (CoreImage image = CoreImage.Load(memoryStream)) + using (Image image = CoreImage.Load(memoryStream)) { return new CoreSize(image.Width, image.Height); } diff --git a/tests/ImageSharp.Benchmarks/Image/DecodeFilteredPng.cs b/tests/ImageSharp.Benchmarks/Image/DecodeFilteredPng.cs index 6786cfdc0..a1fddc502 100644 --- a/tests/ImageSharp.Benchmarks/Image/DecodeFilteredPng.cs +++ b/tests/ImageSharp.Benchmarks/Image/DecodeFilteredPng.cs @@ -10,6 +10,7 @@ namespace ImageSharp.Benchmarks.Image using BenchmarkDotNet.Attributes; using ImageSharp; + using CoreImage = ImageSharp.Image; public class DecodeFilteredPng : BenchmarkBase { @@ -31,7 +32,7 @@ namespace ImageSharp.Benchmarks.Image private Size LoadPng(MemoryStream stream) { - using (Image image = Image.Load(stream)) + using (Image image = CoreImage.Load(stream)) { return new Size(image.Width, image.Height); } diff --git a/tests/ImageSharp.Benchmarks/Image/DecodeGif.cs b/tests/ImageSharp.Benchmarks/Image/DecodeGif.cs index a9bb4c7b3..02620fe74 100644 --- a/tests/ImageSharp.Benchmarks/Image/DecodeGif.cs +++ b/tests/ImageSharp.Benchmarks/Image/DecodeGif.cs @@ -11,6 +11,7 @@ namespace ImageSharp.Benchmarks.Image using BenchmarkDotNet.Attributes; using CoreImage = ImageSharp.Image; + using CoreSize = ImageSharp.Size; public class DecodeGif : BenchmarkBase @@ -43,7 +44,7 @@ namespace ImageSharp.Benchmarks.Image { using (MemoryStream memoryStream = new MemoryStream(this.gifBytes)) { - using (CoreImage image = CoreImage.Load(memoryStream)) + using (Image image = CoreImage.Load(memoryStream)) { return new CoreSize(image.Width, image.Height); } diff --git a/tests/ImageSharp.Benchmarks/Image/DecodeJpeg.cs b/tests/ImageSharp.Benchmarks/Image/DecodeJpeg.cs index 6ce230370..ab45f95f4 100644 --- a/tests/ImageSharp.Benchmarks/Image/DecodeJpeg.cs +++ b/tests/ImageSharp.Benchmarks/Image/DecodeJpeg.cs @@ -11,6 +11,7 @@ namespace ImageSharp.Benchmarks.Image using BenchmarkDotNet.Attributes; using CoreImage = ImageSharp.Image; + using CoreSize = ImageSharp.Size; public class DecodeJpeg : BenchmarkBase @@ -43,7 +44,7 @@ namespace ImageSharp.Benchmarks.Image { using (MemoryStream memoryStream = new MemoryStream(this.jpegBytes)) { - using (CoreImage image = CoreImage.Load(memoryStream)) + using (Image image = CoreImage.Load(memoryStream)) { return new CoreSize(image.Width, image.Height); } diff --git a/tests/ImageSharp.Benchmarks/Image/DecodeJpegMultiple.cs b/tests/ImageSharp.Benchmarks/Image/DecodeJpegMultiple.cs index 5c3c1e115..44c90d253 100644 --- a/tests/ImageSharp.Benchmarks/Image/DecodeJpegMultiple.cs +++ b/tests/ImageSharp.Benchmarks/Image/DecodeJpegMultiple.cs @@ -8,8 +8,7 @@ namespace ImageSharp.Benchmarks.Image using System.Collections.Generic; using BenchmarkDotNet.Attributes; - using Image = ImageSharp.Image; - using ImageSharpSize = ImageSharp.Size; + using CoreImage = ImageSharp.Image; [Config(typeof(Config.Short))] public class DecodeJpegMultiple : MultiImageBenchmarkBase @@ -25,8 +24,8 @@ namespace ImageSharp.Benchmarks.Image public void DecodeJpegImageSharp() { this.ForEachStream( - ms => ImageSharp.Image.Load(ms) - ); + ms => CoreImage.Load(ms) + ); } [Benchmark(Baseline = true, Description = "DecodeJpegMultiple - System.Drawing")] diff --git a/tests/ImageSharp.Benchmarks/Image/DecodePng.cs b/tests/ImageSharp.Benchmarks/Image/DecodePng.cs index 620a48a3b..9b71fd058 100644 --- a/tests/ImageSharp.Benchmarks/Image/DecodePng.cs +++ b/tests/ImageSharp.Benchmarks/Image/DecodePng.cs @@ -11,6 +11,7 @@ namespace ImageSharp.Benchmarks.Image using BenchmarkDotNet.Attributes; using CoreImage = ImageSharp.Image; + using CoreSize = ImageSharp.Size; public class DecodePng : BenchmarkBase @@ -43,7 +44,7 @@ namespace ImageSharp.Benchmarks.Image { using (MemoryStream memoryStream = new MemoryStream(this.pngBytes)) { - using (CoreImage image = CoreImage.Load(memoryStream)) + using (Image image = CoreImage.Load(memoryStream)) { return new CoreSize(image.Width, image.Height); } diff --git a/tests/ImageSharp.Benchmarks/Image/EncodeBmp.cs b/tests/ImageSharp.Benchmarks/Image/EncodeBmp.cs index 6ed577338..52a039912 100644 --- a/tests/ImageSharp.Benchmarks/Image/EncodeBmp.cs +++ b/tests/ImageSharp.Benchmarks/Image/EncodeBmp.cs @@ -10,6 +10,7 @@ namespace ImageSharp.Benchmarks.Image using System.IO; using BenchmarkDotNet.Attributes; + using CoreImage = ImageSharp.Image; public class EncodeBmp : BenchmarkBase @@ -17,7 +18,7 @@ namespace ImageSharp.Benchmarks.Image // System.Drawing needs this. private Stream bmpStream; private Image bmpDrawing; - private CoreImage bmpCore; + private Image bmpCore; [Setup] public void ReadImages() @@ -25,7 +26,7 @@ namespace ImageSharp.Benchmarks.Image if (this.bmpStream == null) { this.bmpStream = File.OpenRead("../ImageSharp.Tests/TestImages/Formats/Bmp/Car.bmp"); - this.bmpCore = CoreImage.Load(this.bmpStream); + this.bmpCore = CoreImage.Load(this.bmpStream); this.bmpStream.Position = 0; this.bmpDrawing = Image.FromStream(this.bmpStream); } diff --git a/tests/ImageSharp.Benchmarks/Image/EncodeGif.cs b/tests/ImageSharp.Benchmarks/Image/EncodeGif.cs index fabeba1bd..5eaa8940b 100644 --- a/tests/ImageSharp.Benchmarks/Image/EncodeGif.cs +++ b/tests/ImageSharp.Benchmarks/Image/EncodeGif.cs @@ -10,6 +10,7 @@ namespace ImageSharp.Benchmarks.Image using System.IO; using BenchmarkDotNet.Attributes; + using CoreImage = ImageSharp.Image; public class EncodeGif : BenchmarkBase @@ -17,7 +18,7 @@ namespace ImageSharp.Benchmarks.Image // System.Drawing needs this. private Stream bmpStream; private Image bmpDrawing; - private CoreImage bmpCore; + private Image bmpCore; [Setup] public void ReadImages() @@ -25,7 +26,7 @@ namespace ImageSharp.Benchmarks.Image if (this.bmpStream == null) { this.bmpStream = File.OpenRead("../ImageSharp.Tests/TestImages/Formats/Bmp/Car.bmp"); - this.bmpCore = CoreImage.Load(this.bmpStream); + this.bmpCore = CoreImage.Load(this.bmpStream); this.bmpStream.Position = 0; this.bmpDrawing = Image.FromStream(this.bmpStream); } diff --git a/tests/ImageSharp.Benchmarks/Image/EncodeIndexedPng.cs b/tests/ImageSharp.Benchmarks/Image/EncodeIndexedPng.cs index b27ad5fcc..4d25c82ef 100644 --- a/tests/ImageSharp.Benchmarks/Image/EncodeIndexedPng.cs +++ b/tests/ImageSharp.Benchmarks/Image/EncodeIndexedPng.cs @@ -11,9 +11,10 @@ namespace ImageSharp.Benchmarks.Image using ImageSharp; using ImageSharp.Formats; - using ImageSharp.PixelFormats; using ImageSharp.Quantizers; + using CoreImage = ImageSharp.Image; + /// /// Benchmarks saving png files using different quantizers. System.Drawing cannot save indexed png files so we cannot compare. /// @@ -21,7 +22,7 @@ namespace ImageSharp.Benchmarks.Image { // System.Drawing needs this. private Stream bmpStream; - private Image bmpCore; + private Image bmpCore; [Params(false)] public bool LargeImage { get; set; } @@ -35,7 +36,7 @@ namespace ImageSharp.Benchmarks.Image ? "../ImageSharp.Tests/TestImages/Formats/Jpg/baseline/jpeg420exif.jpg" : "../ImageSharp.Tests/TestImages/Formats/Bmp/Car.bmp"; this.bmpStream = File.OpenRead(path); - this.bmpCore = Image.Load(this.bmpStream); + this.bmpCore = CoreImage.Load(this.bmpStream); this.bmpStream.Position = 0; } } diff --git a/tests/ImageSharp.Benchmarks/Image/EncodeJpeg.cs b/tests/ImageSharp.Benchmarks/Image/EncodeJpeg.cs index 7649812ec..efd4e8ac5 100644 --- a/tests/ImageSharp.Benchmarks/Image/EncodeJpeg.cs +++ b/tests/ImageSharp.Benchmarks/Image/EncodeJpeg.cs @@ -10,6 +10,7 @@ namespace ImageSharp.Benchmarks.Image using System.IO; using BenchmarkDotNet.Attributes; + using CoreImage = ImageSharp.Image; public class EncodeJpeg : BenchmarkBase @@ -17,7 +18,7 @@ namespace ImageSharp.Benchmarks.Image // System.Drawing needs this. private Stream bmpStream; private Image bmpDrawing; - private CoreImage bmpCore; + private Image bmpCore; [Setup] public void ReadImages() @@ -25,7 +26,7 @@ namespace ImageSharp.Benchmarks.Image if (this.bmpStream == null) { this.bmpStream = File.OpenRead("../ImageSharp.Tests/TestImages/Formats/Bmp/Car.bmp"); - this.bmpCore = CoreImage.Load(this.bmpStream); + this.bmpCore = CoreImage.Load(this.bmpStream); this.bmpStream.Position = 0; this.bmpDrawing = Image.FromStream(this.bmpStream); } diff --git a/tests/ImageSharp.Benchmarks/Image/EncodePng.cs b/tests/ImageSharp.Benchmarks/Image/EncodePng.cs index 6158e5aac..11182ac48 100644 --- a/tests/ImageSharp.Benchmarks/Image/EncodePng.cs +++ b/tests/ImageSharp.Benchmarks/Image/EncodePng.cs @@ -12,7 +12,6 @@ namespace ImageSharp.Benchmarks.Image using BenchmarkDotNet.Attributes; using ImageSharp.Formats; - using ImageSharp.PixelFormats; using ImageSharp.Quantizers; using CoreImage = ImageSharp.Image; @@ -22,7 +21,7 @@ namespace ImageSharp.Benchmarks.Image // System.Drawing needs this. private Stream bmpStream; private Image bmpDrawing; - private CoreImage bmpCore; + private Image bmpCore; [Params(false)] public bool LargeImage { get; set; } @@ -39,7 +38,7 @@ namespace ImageSharp.Benchmarks.Image ? "../ImageSharp.Tests/TestImages/Formats/Jpg/baseline/jpeg420exif.jpg" : "../ImageSharp.Tests/TestImages/Formats/Bmp/Car.bmp"; this.bmpStream = File.OpenRead(path); - this.bmpCore = CoreImage.Load(this.bmpStream); + this.bmpCore = CoreImage.Load(this.bmpStream); this.bmpStream.Position = 0; this.bmpDrawing = Image.FromStream(this.bmpStream); } diff --git a/tests/ImageSharp.Benchmarks/Image/GetSetPixel.cs b/tests/ImageSharp.Benchmarks/Image/GetSetPixel.cs index 21927c915..28616213b 100644 --- a/tests/ImageSharp.Benchmarks/Image/GetSetPixel.cs +++ b/tests/ImageSharp.Benchmarks/Image/GetSetPixel.cs @@ -11,7 +11,6 @@ namespace ImageSharp.Benchmarks.Image using ImageSharp.PixelFormats; - using CoreImage = ImageSharp.Image; using SystemColor = System.Drawing.Color; public class GetSetPixel : BenchmarkBase @@ -29,7 +28,7 @@ namespace ImageSharp.Benchmarks.Image [Benchmark(Description = "ImageSharp GetSet pixel")] public Rgba32 ResizeCore() { - using (CoreImage image = new CoreImage(400, 400)) + using (Image image = new Image(400, 400)) { using (PixelAccessor imagePixels = image.Lock()) { diff --git a/tests/ImageSharp.Benchmarks/Image/MultiImageBenchmarkBase.cs b/tests/ImageSharp.Benchmarks/Image/MultiImageBenchmarkBase.cs index a084ca025..dfee978cc 100644 --- a/tests/ImageSharp.Benchmarks/Image/MultiImageBenchmarkBase.cs +++ b/tests/ImageSharp.Benchmarks/Image/MultiImageBenchmarkBase.cs @@ -15,13 +15,13 @@ namespace ImageSharp.Benchmarks.Image using BenchmarkDotNet.Attributes; - using Image = ImageSharp.Image; + using CoreImage = ImageSharp.Image; public abstract class MultiImageBenchmarkBase : BenchmarkBase { protected Dictionary FileNamesToBytes = new Dictionary(); - protected Dictionary FileNamesToImageSharpImages = new Dictionary(); + protected Dictionary> FileNamesToImageSharpImages = new Dictionary>(); protected Dictionary FileNamesToSystemDrawingImages = new Dictionary(); /// @@ -154,7 +154,7 @@ namespace ImageSharp.Benchmarks.Image using (MemoryStream ms1 = new MemoryStream(bytes)) { - this.FileNamesToImageSharpImages[fn] = Image.Load(ms1); + this.FileNamesToImageSharpImages[fn] = CoreImage.Load(ms1); } @@ -162,7 +162,7 @@ namespace ImageSharp.Benchmarks.Image } } - protected IEnumerable> FileNames2ImageSharpImages + protected IEnumerable>> FileNames2ImageSharpImages => this.EnumeratePairsByBenchmarkSettings( this.FileNamesToImageSharpImages, @@ -176,9 +176,9 @@ namespace ImageSharp.Benchmarks.Image protected virtual int LargeImageThresholdInPixels => 700000; - protected void ForEachImageSharpImage(Func operation) + protected void ForEachImageSharpImage(Func, object> operation) { - foreach (KeyValuePair kv in this.FileNames2ImageSharpImages) + foreach (KeyValuePair> kv in this.FileNames2ImageSharpImages) { try { @@ -194,7 +194,7 @@ namespace ImageSharp.Benchmarks.Image } } - protected void ForEachImageSharpImage(Func operation) + protected void ForEachImageSharpImage(Func, MemoryStream, object> operation) { using (MemoryStream workStream = new MemoryStream()) { diff --git a/tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs b/tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs index a616733b5..1da69f1a8 100644 --- a/tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs +++ b/tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs @@ -5,19 +5,19 @@ namespace ImageSharp.Benchmarks { + using System; using BenchmarkDotNet.Attributes; using ImageSharp.PixelFormats; - using ImageSharp.Drawing; - using ImageSharp.Processing.Processors; - using CoreImage = ImageSharp.Image; using CoreSize = ImageSharp.Size; using System.Numerics; + + using ImageSharp.Memory; using ImageSharp.PixelFormats.PixelBlenders; public class PorterDuffBulkVsPixel : BenchmarkBase { - private void BulkVectorConvert(BufferSpan destination, BufferSpan background, BufferSpan source, BufferSpan amount) + private void BulkVectorConvert(Span destination, Span background, Span source, Span amount) where TPixel : struct, IPixel { Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length)); @@ -26,9 +26,9 @@ namespace ImageSharp.Benchmarks using (Buffer buffer = new Buffer(destination.Length * 3)) { - BufferSpan destinationSpan = buffer.Slice(0, destination.Length); - BufferSpan backgroundSpan = buffer.Slice(destination.Length, destination.Length); - BufferSpan sourceSpan = buffer.Slice(destination.Length * 2, destination.Length); + Span destinationSpan = buffer.Slice(0, destination.Length); + Span backgroundSpan = buffer.Slice(destination.Length, destination.Length); + Span sourceSpan = buffer.Slice(destination.Length * 2, destination.Length); PixelOperations.Instance.ToVector4(background, backgroundSpan, destination.Length); PixelOperations.Instance.ToVector4(source, sourceSpan, destination.Length); @@ -41,7 +41,7 @@ namespace ImageSharp.Benchmarks PixelOperations.Instance.PackFromVector4(destinationSpan, destination, destination.Length); } } - private void BulkPixelConvert(BufferSpan destination, BufferSpan background, BufferSpan source, BufferSpan amount) + private void BulkPixelConvert(Span destination, Span background, Span source, Span amount) where TPixel : struct, IPixel { Guard.MustBeGreaterThanOrEqualTo(destination.Length, background.Length, nameof(destination)); @@ -57,7 +57,7 @@ namespace ImageSharp.Benchmarks [Benchmark(Description = "ImageSharp BulkVectorConvert")] public CoreSize BulkVectorConvert() { - using (CoreImage image = new CoreImage(800, 800)) + using (Image image = new Image(800, 800)) { Buffer amounts = new Buffer(image.Width); @@ -69,7 +69,7 @@ namespace ImageSharp.Benchmarks { for (int y = 0; y < image.Height; y++) { - BufferSpan span = pixels.GetRowSpan(y); + Span span = pixels.GetRowSpan(y); BulkVectorConvert(span, span, span, amounts); } } @@ -80,7 +80,7 @@ namespace ImageSharp.Benchmarks [Benchmark(Description = "ImageSharp BulkPixelConvert")] public CoreSize BulkPixelConvert() { - using (CoreImage image = new CoreImage(800, 800)) + using (Image image = new Image(800, 800)) { Buffer amounts = new Buffer(image.Width); @@ -92,7 +92,7 @@ namespace ImageSharp.Benchmarks { for (int y = 0; y < image.Height; y++) { - BufferSpan span = pixels.GetRowSpan(y); + Span span = pixels.GetRowSpan(y); BulkPixelConvert(span, span, span, amounts); } } diff --git a/tests/ImageSharp.Benchmarks/Samplers/Crop.cs b/tests/ImageSharp.Benchmarks/Samplers/Crop.cs index a3cdef92e..9fa979463 100644 --- a/tests/ImageSharp.Benchmarks/Samplers/Crop.cs +++ b/tests/ImageSharp.Benchmarks/Samplers/Crop.cs @@ -10,7 +10,8 @@ namespace ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; - using CoreImage = ImageSharp.Image; + using ImageSharp.PixelFormats; + using CoreSize = ImageSharp.Size; public class Crop : BenchmarkBase @@ -38,7 +39,7 @@ namespace ImageSharp.Benchmarks [Benchmark(Description = "ImageSharp Crop")] public CoreSize CropResizeCore() { - using (CoreImage image = new CoreImage(800, 800)) + using (Image image = new Image(800, 800)) { image.Crop(100, 100); return new CoreSize(image.Width, image.Height); diff --git a/tests/ImageSharp.Benchmarks/Samplers/DetectEdges.cs b/tests/ImageSharp.Benchmarks/Samplers/DetectEdges.cs index 28661b9d6..d4920ff08 100644 --- a/tests/ImageSharp.Benchmarks/Samplers/DetectEdges.cs +++ b/tests/ImageSharp.Benchmarks/Samplers/DetectEdges.cs @@ -9,12 +9,13 @@ namespace ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; - using CoreImage = ImageSharp.Image; using Processing; + using CoreImage = ImageSharp.Image; + public class DetectEdges : BenchmarkBase { - private CoreImage image; + private Image image; [Setup] public void ReadImage() @@ -23,7 +24,7 @@ namespace ImageSharp.Benchmarks { using (FileStream stream = File.OpenRead("../ImageSharp.Tests/TestImages/Formats/Bmp/Car.bmp")) { - this.image = CoreImage.Load(stream); + this.image = CoreImage.Load(stream); } } } diff --git a/tests/ImageSharp.Benchmarks/Samplers/Glow.cs b/tests/ImageSharp.Benchmarks/Samplers/Glow.cs index 6daf120fa..7608d3065 100644 --- a/tests/ImageSharp.Benchmarks/Samplers/Glow.cs +++ b/tests/ImageSharp.Benchmarks/Samplers/Glow.cs @@ -8,15 +8,15 @@ namespace ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; using ImageSharp.PixelFormats; - using ImageSharp.Drawing; using ImageSharp.Processing.Processors; - using CoreImage = ImageSharp.Image; using CoreSize = ImageSharp.Size; using ImageSharp.Processing; using System.Numerics; using System; using System.Threading.Tasks; + using ImageSharp.Memory; + public class Glow : BenchmarkBase { private GlowProcessor bulk; @@ -32,7 +32,7 @@ namespace ImageSharp.Benchmarks [Benchmark(Description = "ImageSharp Glow - Bulk")] public CoreSize GlowBulk() { - using (CoreImage image = new CoreImage(800, 800)) + using (Image image = new Image(800, 800)) { image.ApplyProcessor(bulk, image.Bounds); return new CoreSize(image.Width, image.Height); @@ -42,7 +42,7 @@ namespace ImageSharp.Benchmarks [Benchmark(Description = "ImageSharp Glow - Parallel")] public CoreSize GLowSimple() { - using (CoreImage image = new CoreImage(800, 800)) + using (Image image = new Image(800, 800)) { image.ApplyProcessor(parallel, image.Bounds); return new CoreSize(image.Width, image.Height); diff --git a/tests/ImageSharp.Benchmarks/Samplers/Resize.cs b/tests/ImageSharp.Benchmarks/Samplers/Resize.cs index 932c229bd..d96be70f7 100644 --- a/tests/ImageSharp.Benchmarks/Samplers/Resize.cs +++ b/tests/ImageSharp.Benchmarks/Samplers/Resize.cs @@ -13,8 +13,6 @@ namespace ImageSharp.Benchmarks using ImageSharp.PixelFormats; using CoreSize = ImageSharp.Size; - using CoreImage = ImageSharp.Image; - using CoreImageVector = ImageSharp.Image; public class Resize : BenchmarkBase { @@ -41,41 +39,41 @@ namespace ImageSharp.Benchmarks [Benchmark(Description = "ImageSharp Resize")] public CoreSize ResizeCore() { - using (CoreImage image = new CoreImage(2000, 2000)) + using (Image image = new Image(2000, 2000)) { image.Resize(400, 400); return new CoreSize(image.Width, image.Height); } } - [Benchmark(Description = "ImageSharp Vector Resize")] - public CoreSize ResizeCoreVector() - { - using (CoreImageVector image = new CoreImageVector(2000, 2000)) - { - image.Resize(400, 400); - return new CoreSize(image.Width, image.Height); - } - } + //[Benchmark(Description = "ImageSharp Vector Resize")] + //public CoreSize ResizeCoreVector() + //{ + // using (Image image = new Image(2000, 2000)) + // { + // image.Resize(400, 400); + // return new CoreSize(image.Width, image.Height); + // } + //} - [Benchmark(Description = "ImageSharp Compand Resize")] - public CoreSize ResizeCoreCompand() - { - using (CoreImage image = new CoreImage(2000, 2000)) - { - image.Resize(400, 400, true); - return new CoreSize(image.Width, image.Height); - } - } + //[Benchmark(Description = "ImageSharp Compand Resize")] + //public CoreSize ResizeCoreCompand() + //{ + // using (Image image = new Image(2000, 2000)) + // { + // image.Resize(400, 400, true); + // return new CoreSize(image.Width, image.Height); + // } + //} - [Benchmark(Description = "ImageSharp Vector Compand Resize")] - public CoreSize ResizeCoreVectorCompand() - { - using (CoreImageVector image = new CoreImageVector(2000, 2000)) - { - image.Resize(400, 400, true); - return new CoreSize(image.Width, image.Height); - } - } + //[Benchmark(Description = "ImageSharp Vector Compand Resize")] + //public CoreSize ResizeCoreVectorCompand() + //{ + // using (Image image = new Image(2000, 2000)) + // { + // image.Resize(400, 400, true); + // return new CoreSize(image.Width, image.Height); + // } + //} } } diff --git a/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj b/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj index 23a5c59a3..53cdffaea 100644 --- a/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj +++ b/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj @@ -29,4 +29,7 @@ + + + \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Colors/PixelOperationsTests.cs b/tests/ImageSharp.Tests/Colors/PixelOperationsTests.cs index 3d0392753..c91218ccc 100644 --- a/tests/ImageSharp.Tests/Colors/PixelOperationsTests.cs +++ b/tests/ImageSharp.Tests/Colors/PixelOperationsTests.cs @@ -5,6 +5,7 @@ namespace ImageSharp.Tests.Colors using System; using System.Numerics; + using ImageSharp.Memory; using ImageSharp.PixelFormats; using Xunit; @@ -12,7 +13,7 @@ namespace ImageSharp.Tests.Colors public class PixelOperationsTests { - public class Color32 : BulkPixelOperationsTests + public class Color32 : PixelOperationsTests { public Color32(ITestOutputHelper output) : base(output) @@ -20,7 +21,7 @@ namespace ImageSharp.Tests.Colors } // For 4.6 test runner MemberData does not work without redeclaring the public field in the derived test class: - //public static new TheoryData ArraySizesData => new TheoryData { 7, 16, 1111 }; + public static new TheoryData ArraySizesData => new TheoryData { 7, 16, 1111 }; [Fact] public void IsSpecialImplementation() @@ -60,7 +61,7 @@ namespace ImageSharp.Tests.Colors } } - public class Argb : BulkPixelOperationsTests + public class Argb : PixelOperationsTests { // For 4.6 test runner MemberData does not work without redeclaring the public field in the derived test class: public Argb(ITestOutputHelper output) @@ -68,7 +69,7 @@ namespace ImageSharp.Tests.Colors { } - //public static new TheoryData ArraySizesData => new TheoryData { 7, 16, 1111 }; + public static new TheoryData ArraySizesData => new TheoryData { 7, 16, 1111 }; } [Theory] @@ -80,10 +81,10 @@ namespace ImageSharp.Tests.Colors } } - public abstract class BulkPixelOperationsTests : MeasureFixture + public abstract class PixelOperationsTests : MeasureFixture where TPixel : struct, IPixel { - protected BulkPixelOperationsTests(ITestOutputHelper output) + protected PixelOperationsTests(ITestOutputHelper output) : base(output) { } @@ -316,8 +317,8 @@ namespace ImageSharp.Tests.Colors public Buffer ActualDestBuffer { get; } public Buffer ExpectedDestBuffer { get; } - public BufferSpan Source => this.SourceBuffer; - public BufferSpan ActualDest => this.ActualDestBuffer; + public Span Source => this.SourceBuffer; + public Span ActualDest => this.ActualDestBuffer; public TestBuffers(TSource[] source, TDest[] expectedDest) { @@ -366,13 +367,13 @@ namespace ImageSharp.Tests.Colors internal static void TestOperation( TSource[] source, TDest[] expected, - Action, BufferSpan> action) + Action, Buffer> action) where TSource : struct where TDest : struct { using (TestBuffers buffers = new TestBuffers(source, expected)) { - action(buffers.Source, buffers.ActualDest); + action(buffers.Source, buffers.ActualDestBuffer); buffers.Verify(); } } diff --git a/tests/ImageSharp.Tests/Common/Buffer2DTests.cs b/tests/ImageSharp.Tests/Common/Buffer2DTests.cs index ac92ab87b..5f44a132d 100644 --- a/tests/ImageSharp.Tests/Common/Buffer2DTests.cs +++ b/tests/ImageSharp.Tests/Common/Buffer2DTests.cs @@ -4,6 +4,8 @@ namespace ImageSharp.Tests.Common using System; using System.Runtime.CompilerServices; + using ImageSharp.Memory; + using Xunit; using static TestStructs; @@ -13,7 +15,7 @@ namespace ImageSharp.Tests.Common // ReSharper disable once ClassNeverInstantiated.Local private class Assert : Xunit.Assert { - public static void SpanPointsTo(BufferSpan span, Buffer buffer, int bufferOffset = 0) + public static void SpanPointsTo(Span span, Buffer buffer, int bufferOffset = 0) where T : struct { ref T actual = ref span.DangerousGetPinnableReference(); @@ -75,9 +77,9 @@ namespace ImageSharp.Tests.Common { using (Buffer2D buffer = new Buffer2D(width, height)) { - BufferSpan span = buffer.GetRowSpan(y); + Span span = buffer.GetRowSpan(y); - Assert.Equal(width * y, span.Start); + // Assert.Equal(width * y, span.Start); Assert.Equal(width, span.Length); Assert.SpanPointsTo(span, buffer, width * y); } @@ -91,9 +93,9 @@ namespace ImageSharp.Tests.Common { using (Buffer2D buffer = new Buffer2D(width, height)) { - BufferSpan span = buffer.GetRowSpan(x, y); + Span span = buffer.GetRowSpan(x, y); - Assert.Equal(width * y + x, span.Start); + // Assert.Equal(width * y + x, span.Start); Assert.Equal(width - x, span.Length); Assert.SpanPointsTo(span, buffer, width * y + x); } diff --git a/tests/ImageSharp.Tests/Common/BufferSpanTests.cs b/tests/ImageSharp.Tests/Common/BufferSpanTests.cs index 3bc59df64..af33a981b 100644 --- a/tests/ImageSharp.Tests/Common/BufferSpanTests.cs +++ b/tests/ImageSharp.Tests/Common/BufferSpanTests.cs @@ -4,15 +4,17 @@ namespace ImageSharp.Tests.Common { using System; + using System.Numerics; using System.Runtime.CompilerServices; + using ImageSharp.Memory; using ImageSharp.PixelFormats; using Xunit; using static TestStructs; - public unsafe class BufferSpanTests + public unsafe class SpanTests { // ReSharper disable once ClassNeverInstantiated.Local private class Assert : Xunit.Assert @@ -25,6 +27,21 @@ namespace ImageSharp.Tests.Common } } + [Fact] + public void FetchVector() + { + float[] stuff = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; + + Span span = new Span(stuff); + + ref Vector v = ref span.FetchVector(); + + Assert.Equal(0, v[0]); + Assert.Equal(1, v[1]); + Assert.Equal(2, v[2]); + Assert.Equal(3, v[3]); + } + [Fact] public void AsBytes() { @@ -32,10 +49,10 @@ namespace ImageSharp.Tests.Common using (Buffer colorBuf = new Buffer(fooz)) { - BufferSpan orig = colorBuf.Slice(1); - BufferSpan asBytes = orig.AsBytes(); + Span orig = colorBuf.Slice(1); + Span asBytes = orig.AsBytes(); - Assert.Equal(asBytes.Start, sizeof(Foo)); + // Assert.Equal(asBytes.Start, sizeof(Foo)); Assert.Equal(orig.Length * Unsafe.SizeOf(), asBytes.Length); Assert.SameRefs(ref orig.DangerousGetPinnableReference(), ref asBytes.DangerousGetPinnableReference()); } @@ -49,10 +66,10 @@ namespace ImageSharp.Tests.Common Foo[] array = Foo.CreateArray(3); // Act: - BufferSpan span = new BufferSpan(array); + Span span = new Span(array); // Assert: - Assert.Equal(array, span.Array); + Assert.Equal(array, span.ToArray()); Assert.Equal(3, span.Length); Assert.SameRefs(ref array[0], ref span.DangerousGetPinnableReference()); } @@ -64,11 +81,9 @@ namespace ImageSharp.Tests.Common int start = 2; // Act: - BufferSpan span = new BufferSpan(array, start); + Span span = new Span(array, start); // Assert: - Assert.Equal(array, span.Array); - Assert.Equal(start, span.Start); Assert.SameRefs(ref array[start], ref span.DangerousGetPinnableReference()); Assert.Equal(array.Length - start, span.Length); } @@ -80,11 +95,9 @@ namespace ImageSharp.Tests.Common int start = 2; int length = 3; // Act: - BufferSpan span = new BufferSpan(array, start, length); + Span span = new Span(array, start, length); // Assert: - Assert.Equal(array, span.Array); - Assert.Equal(start, span.Start); Assert.SameRefs(ref array[start], ref span.DangerousGetPinnableReference()); Assert.Equal(length, span.Length); } @@ -100,14 +113,12 @@ namespace ImageSharp.Tests.Common int start1 = 2; int totalOffset = start0 + start1; - BufferSpan span = new BufferSpan(array, start0); + Span span = new Span(array, start0); // Act: span = span.Slice(start1); // Assert: - Assert.Equal(array, span.Array); - Assert.Equal(totalOffset, span.Start); Assert.SameRefs(ref array[totalOffset], ref span.DangerousGetPinnableReference()); Assert.Equal(array.Length - totalOffset, span.Length); } @@ -121,37 +132,35 @@ namespace ImageSharp.Tests.Common int totalOffset = start0 + start1; int sliceLength = 3; - BufferSpan span = new BufferSpan(array, start0); + Span span = new Span(array, start0); // Act: span = span.Slice(start1, sliceLength); // Assert: - Assert.Equal(array, span.Array); - Assert.Equal(totalOffset, span.Start); Assert.SameRefs(ref array[totalOffset], ref span.DangerousGetPinnableReference()); Assert.Equal(sliceLength, span.Length); } } - [Theory] - [InlineData(4)] - [InlineData(1500)] - public void Clear(int count) - { - Foo[] array = Foo.CreateArray(count + 42); + //[Theory] + //[InlineData(4)] + //[InlineData(1500)] + //public void Clear(int count) + //{ + // Foo[] array = Foo.CreateArray(count + 42); - int offset = 2; - BufferSpan ap = new BufferSpan(array, offset); + // int offset = 2; + // Span ap = new Span(array, offset); - // Act: - ap.Clear(count); + // // Act: + // ap.Clear(count); - Assert.NotEqual(default(Foo), array[offset - 1]); - Assert.Equal(default(Foo), array[offset]); - Assert.Equal(default(Foo), array[offset + count - 1]); - Assert.NotEqual(default(Foo), array[offset + count]); - } + // Assert.NotEqual(default(Foo), array[offset - 1]); + // Assert.Equal(default(Foo), array[offset]); + // Assert.Equal(default(Foo), array[offset + count - 1]); + // Assert.NotEqual(default(Foo), array[offset + count]); + //} public class Indexer { @@ -171,7 +180,7 @@ namespace ImageSharp.Tests.Common public void Read(int length, int start, int index) { Foo[] a = Foo.CreateArray(length); - BufferSpan span = new BufferSpan(a, start); + Span span = new Span(a, start); Foo element = span[index]; @@ -183,7 +192,7 @@ namespace ImageSharp.Tests.Common public void Write(int length, int start, int index) { Foo[] a = Foo.CreateArray(length); - BufferSpan span = new BufferSpan(a, start); + Span span = new Span(a, start); span[index] = new Foo(666, 666); @@ -198,9 +207,9 @@ namespace ImageSharp.Tests.Common public void AsBytes_Read(int length, int start, int index, int byteOffset) { Foo[] a = Foo.CreateArray(length); - BufferSpan span = new BufferSpan(a, start); + Span span = new Span(a, start); - BufferSpan bytes = span.AsBytes(); + Span bytes = span.AsBytes(); byte actual = bytes[index * Unsafe.SizeOf() + byteOffset]; @@ -218,7 +227,7 @@ namespace ImageSharp.Tests.Common public void DangerousGetPinnableReference(int start, int length) { Foo[] a = Foo.CreateArray(length); - BufferSpan span = new BufferSpan(a, start); + Span span = new Span(a, start); ref Foo r = ref span.DangerousGetPinnableReference(); Assert.True(Unsafe.AreSame(ref a[start], ref r)); @@ -260,10 +269,10 @@ namespace ImageSharp.Tests.Common Foo[] source = Foo.CreateArray(count + 2); Foo[] dest = new Foo[count + 5]; - BufferSpan apSource = new BufferSpan(source, 1); - BufferSpan apDest = new BufferSpan(dest, 1); + Span apSource = new Span(source, 1); + Span apDest = new Span(dest, 1); - BufferSpan.Copy(apSource, apDest, count - 1); + SpanHelper.Copy(apSource, apDest, count - 1); AssertNotDefault(source, 1); AssertNotDefault(dest, 1); @@ -283,10 +292,10 @@ namespace ImageSharp.Tests.Common AlignedFoo[] source = AlignedFoo.CreateArray(count + 2); AlignedFoo[] dest = new AlignedFoo[count + 5]; - BufferSpan apSource = new BufferSpan(source, 1); - BufferSpan apDest = new BufferSpan(dest, 1); + Span apSource = new Span(source, 1); + Span apDest = new Span(dest, 1); - BufferSpan.Copy(apSource, apDest, count - 1); + SpanHelper.Copy(apSource, apDest, count - 1); AssertNotDefault(source, 1); AssertNotDefault(dest, 1); @@ -306,10 +315,10 @@ namespace ImageSharp.Tests.Common int[] source = CreateTestInts(count + 2); int[] dest = new int[count + 5]; - BufferSpan apSource = new BufferSpan(source, 1); - BufferSpan apDest = new BufferSpan(dest, 1); + Span apSource = new Span(source, 1); + Span apDest = new Span(dest, 1); - BufferSpan.Copy(apSource, apDest, count - 1); + SpanHelper.Copy(apSource, apDest, count - 1); AssertNotDefault(source, 1); AssertNotDefault(dest, 1); @@ -330,10 +339,10 @@ namespace ImageSharp.Tests.Common Foo[] source = Foo.CreateArray(count + 2); byte[] dest = new byte[destCount + sizeof(Foo) * 2]; - BufferSpan apSource = new BufferSpan(source, 1); - BufferSpan apDest = new BufferSpan(dest, sizeof(Foo)); + Span apSource = new Span(source, 1); + Span apDest = new Span(dest, sizeof(Foo)); - BufferSpan.Copy(apSource.AsBytes(), apDest, (count - 1) * sizeof(Foo)); + SpanHelper.Copy(apSource.AsBytes(), apDest, (count - 1) * sizeof(Foo)); AssertNotDefault(source, 1); @@ -353,10 +362,10 @@ namespace ImageSharp.Tests.Common AlignedFoo[] source = AlignedFoo.CreateArray(count + 2); byte[] dest = new byte[destCount + sizeof(AlignedFoo) * 2]; - BufferSpan apSource = new BufferSpan(source, 1); - BufferSpan apDest = new BufferSpan(dest, sizeof(AlignedFoo)); + Span apSource = new Span(source, 1); + Span apDest = new Span(dest, sizeof(AlignedFoo)); - BufferSpan.Copy(apSource.AsBytes(), apDest, (count - 1) * sizeof(AlignedFoo)); + SpanHelper.Copy(apSource.AsBytes(), apDest, (count - 1) * sizeof(AlignedFoo)); AssertNotDefault(source, 1); @@ -376,10 +385,10 @@ namespace ImageSharp.Tests.Common int[] source = CreateTestInts(count + 2); byte[] dest = new byte[destCount + sizeof(int) + 1]; - BufferSpan apSource = new BufferSpan(source); - BufferSpan apDest = new BufferSpan(dest); + Span apSource = new Span(source); + Span apDest = new Span(dest); - BufferSpan.Copy(apSource.AsBytes(), apDest, count * sizeof(int)); + SpanHelper.Copy(apSource.AsBytes(), apDest, count * sizeof(int)); AssertNotDefault(source, 1); @@ -397,10 +406,10 @@ namespace ImageSharp.Tests.Common byte[] source = CreateTestBytes(srcCount); Foo[] dest = new Foo[count + 2]; - BufferSpan apSource = new BufferSpan(source); - BufferSpan apDest = new BufferSpan(dest); + Span apSource = new Span(source); + Span apDest = new Span(dest); - BufferSpan.Copy(apSource, apDest.AsBytes(), count * sizeof(Foo)); + SpanHelper.Copy(apSource, apDest.AsBytes(), count * sizeof(Foo)); AssertNotDefault(source, sizeof(Foo) + 1); AssertNotDefault(dest, 1); @@ -419,7 +428,7 @@ namespace ImageSharp.Tests.Common using (Buffer colorBuf = new Buffer(colors)) using (Buffer byteBuf = new Buffer(colors.Length * 4)) { - BufferSpan.Copy(colorBuf.Span.AsBytes(), byteBuf, colorBuf.Length * sizeof(Rgba32)); + SpanHelper.Copy(colorBuf.Span.AsBytes(), byteBuf, colorBuf.Length * sizeof(Rgba32)); byte[] a = byteBuf.Array; diff --git a/tests/ImageSharp.Tests/Common/BufferTests.cs b/tests/ImageSharp.Tests/Common/BufferTests.cs index 23205d012..010bf40b3 100644 --- a/tests/ImageSharp.Tests/Common/BufferTests.cs +++ b/tests/ImageSharp.Tests/Common/BufferTests.cs @@ -6,6 +6,8 @@ namespace ImageSharp.Tests.Common using System.Runtime.InteropServices; using System.Threading.Tasks; + using ImageSharp.Memory; + using Xunit; using static TestStructs; @@ -15,7 +17,7 @@ namespace ImageSharp.Tests.Common // ReSharper disable once ClassNeverInstantiated.Local private class Assert : Xunit.Assert { - public static void SpanPointsTo(BufferSpan span, Buffer buffer, int bufferOffset = 0) + public static void SpanPointsTo(Span span, Buffer buffer, int bufferOffset = 0) where T : struct { ref T actual = ref span.DangerousGetPinnableReference(); @@ -58,10 +60,8 @@ namespace ImageSharp.Tests.Common } } - [Theory] - [InlineData(42)] - [InlineData(1111)] - public void Clear(int count) + [Fact] + public void Clear() { Foo[] a = { new Foo() { A = 1, B = 2 }, new Foo() { A = 3, B = 4 } }; using (Buffer buffer = new Buffer(a)) @@ -144,10 +144,10 @@ namespace ImageSharp.Tests.Common { using (Buffer buffer = new Buffer(bufferLength)) { - BufferSpan span = buffer; + Span span = buffer; - Assert.Equal(buffer.Array, span.Array); - Assert.Equal(0, span.Start); + //Assert.Equal(buffer.Array, span.ToArray()); + //Assert.Equal(0, span.Start); Assert.SpanPointsTo(span, buffer); Assert.Equal(span.Length, bufferLength); } @@ -158,10 +158,10 @@ namespace ImageSharp.Tests.Common { using (Buffer buffer = new Buffer(42)) { - BufferSpan span = buffer.Span; + Span span = buffer.Span; - Assert.Equal(buffer.Array, span.Array); - Assert.Equal(0, span.Start); + // Assert.Equal(buffer.Array, span.ToArray()); + // Assert.Equal(0, span.Start); Assert.SpanPointsTo(span, buffer); Assert.Equal(span.Length, 42); } @@ -177,10 +177,8 @@ namespace ImageSharp.Tests.Common { using (Buffer buffer = new Buffer(bufferLength)) { - BufferSpan span = buffer.Slice(start); + Span span = buffer.Slice(start); - Assert.Equal(buffer.Array, span.Array); - Assert.Equal(start, span.Start); Assert.SpanPointsTo(span, buffer, start); Assert.Equal(span.Length, bufferLength - start); } @@ -193,10 +191,8 @@ namespace ImageSharp.Tests.Common { using (Buffer buffer = new Buffer(bufferLength)) { - BufferSpan span = buffer.Slice(start, spanLength); + Span span = buffer.Slice(start, spanLength); - Assert.Equal(buffer.Array, span.Array); - Assert.Equal(start, span.Start); Assert.SpanPointsTo(span, buffer, start); Assert.Equal(span.Length, spanLength); } diff --git a/tests/ImageSharp.Tests/Common/Fast2DArrayTests.cs b/tests/ImageSharp.Tests/Common/Fast2DArrayTests.cs index 7db7a4820..efdcaa848 100644 --- a/tests/ImageSharp.Tests/Common/Fast2DArrayTests.cs +++ b/tests/ImageSharp.Tests/Common/Fast2DArrayTests.cs @@ -7,6 +7,8 @@ namespace ImageSharp.Tests.Common { using System; + using ImageSharp.Memory; + using Xunit; public class Fast2DArrayTests diff --git a/tests/ImageSharp.Tests/Common/PixelDataPoolTests.cs b/tests/ImageSharp.Tests/Common/PixelDataPoolTests.cs index e673b28f1..1291160b2 100644 --- a/tests/ImageSharp.Tests/Common/PixelDataPoolTests.cs +++ b/tests/ImageSharp.Tests/Common/PixelDataPoolTests.cs @@ -8,6 +8,7 @@ namespace ImageSharp.Tests { using System.Linq; + using ImageSharp.Memory; using ImageSharp.PixelFormats; using Xunit; diff --git a/tests/ImageSharp.Tests/ConfigurationTests.cs b/tests/ImageSharp.Tests/ConfigurationTests.cs index c749239d7..aa3c4edfc 100644 --- a/tests/ImageSharp.Tests/ConfigurationTests.cs +++ b/tests/ImageSharp.Tests/ConfigurationTests.cs @@ -7,10 +7,13 @@ namespace ImageSharp.Tests { using System; using System.Collections.Generic; + using System.IO; using System.Linq; using ImageSharp.Formats; using ImageSharp.IO; + using ImageSharp.PixelFormats; + using Xunit; /// @@ -21,7 +24,7 @@ namespace ImageSharp.Tests [Fact] public void DefaultsToLocalFileSystem() { - Configuration configuration = Configuration.CreateDefaultInstance(); + var configuration = Configuration.CreateDefaultInstance(); ImageSharp.IO.IFileSystem fs = configuration.FileSystem; @@ -31,7 +34,7 @@ namespace ImageSharp.Tests [Fact] public void IfAutoloadWellknwonFormatesIsTrueAllFormateAreLoaded() { - Configuration configuration = Configuration.CreateDefaultInstance(); + var configuration = Configuration.CreateDefaultInstance(); Assert.Equal(4, configuration.ImageFormats.Count); } @@ -93,7 +96,7 @@ namespace ImageSharp.Tests [Fact] public void TestAddImageFormatThrowsWithNullEncoder() { - TestFormat format = new TestFormat { Encoder = null }; + var format = new TestFormat { Encoder = null }; Assert.Throws(() => { @@ -108,7 +111,7 @@ namespace ImageSharp.Tests [Fact] public void TestAddImageFormatThrowsWithNullDecoder() { - TestFormat format = new TestFormat { Decoder = null }; + var format = new TestFormat { Decoder = null }; Assert.Throws(() => { @@ -123,7 +126,7 @@ namespace ImageSharp.Tests [Fact] public void TestAddImageFormatThrowsWithNullOrEmptyMimeType() { - TestFormat format = new TestFormat { MimeType = null }; + var format = new TestFormat { MimeType = null }; Assert.Throws(() => { @@ -145,7 +148,7 @@ namespace ImageSharp.Tests [Fact] public void TestAddImageFormatThrowsWithNullOrEmptyExtension() { - TestFormat format = new TestFormat { Extension = null }; + var format = new TestFormat { Extension = null }; Assert.Throws(() => { @@ -167,7 +170,7 @@ namespace ImageSharp.Tests [Fact] public void TestAddImageFormatThrowsWenSupportedExtensionsIsNullOrEmpty() { - TestFormat format = new TestFormat { SupportedExtensions = null }; + var format = new TestFormat { SupportedExtensions = null }; Assert.Throws(() => { @@ -189,7 +192,7 @@ namespace ImageSharp.Tests [Fact] public void TestAddImageFormatThrowsWithoutDefaultExtension() { - TestFormat format = new TestFormat { Extension = "test" }; + var format = new TestFormat { Extension = "test" }; Assert.Throws(() => { @@ -204,7 +207,7 @@ namespace ImageSharp.Tests [Fact] public void TestAddImageFormatThrowsWithEmptySupportedExtension() { - TestFormat format = new TestFormat + var format = new TestFormat { Extension = "test", SupportedExtensions = new[] { "test", string.Empty } @@ -236,7 +239,7 @@ namespace ImageSharp.Tests { Configuration.Default.AddImageFormat(new PngFormat()); - Image image = new Image(1, 1); + var image = new Image(1, 1); Assert.Equal(image.Configuration.ParallelOptions, Configuration.Default.ParallelOptions); Assert.Equal(image.Configuration.ImageFormats, Configuration.Default.ImageFormats); } @@ -249,8 +252,8 @@ namespace ImageSharp.Tests { Configuration.Default.AddImageFormat(new PngFormat()); - Image image = new Image(1, 1); - Image image2 = new Image(image); + var image = new Image(1, 1); + var image2 = new Image(image); Assert.Equal(image2.Configuration.ParallelOptions, image.Configuration.ParallelOptions); Assert.True(image2.Configuration.ImageFormats.SequenceEqual(image.Configuration.ImageFormats)); } diff --git a/tests/ImageSharp.Tests/Drawing/BeziersTests.cs b/tests/ImageSharp.Tests/Drawing/BeziersTests.cs index eb3a5de86..ff6892199 100644 --- a/tests/ImageSharp.Tests/Drawing/BeziersTests.cs +++ b/tests/ImageSharp.Tests/Drawing/BeziersTests.cs @@ -22,7 +22,7 @@ namespace ImageSharp.Tests.Drawing public void ImageShouldBeOverlayedByBezierLine() { string path = this.CreateOutputDirectory("Drawing", "BezierLine"); - using (Image image = new Image(500, 500)) + using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { @@ -64,7 +64,7 @@ namespace ImageSharp.Tests.Drawing Rgba32 color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150); - using (Image image = new Image(500, 500)) + using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) { diff --git a/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs b/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs index 674823d3a..7d54879c3 100644 --- a/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs +++ b/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs @@ -20,7 +20,7 @@ namespace ImageSharp.Tests.Drawing public void ImageShouldBeOverlayedByPath() { string path = this.CreateOutputDirectory("Drawing", "Path"); - using (Image image = new Image(500, 500)) + using (Image image = new Image(500, 500)) { LinearLineSegment linerSegemnt = new LinearLineSegment( new Vector2(10, 10), @@ -74,7 +74,7 @@ namespace ImageSharp.Tests.Drawing ShapePath p = new ShapePath(linerSegemnt, bazierSegment); - using (Image image = new Image(500, 500)) + using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) { diff --git a/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs b/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs index 493bab347..7bacebe42 100644 --- a/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs @@ -10,6 +10,7 @@ namespace ImageSharp.Tests.Drawing using ImageSharp.Drawing; using ImageSharp.Drawing.Brushes; + using ImageSharp.Memory; using ImageSharp.PixelFormats; using Xunit; @@ -18,7 +19,7 @@ namespace ImageSharp.Tests.Drawing private void Test(string name, Rgba32 background, IBrush brush, Rgba32[,] expectedPattern) { string path = this.CreateOutputDirectory("Fill", "PatternBrush"); - using (Image image = new Image(20, 20)) + using (Image image = new Image(20, 20)) { image .Fill(background) diff --git a/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs b/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs index 9661a41bb..c7b789da0 100644 --- a/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs @@ -16,7 +16,7 @@ namespace ImageSharp.Tests.Drawing [InlineData(true, 2, 4)] [InlineData(true, 5, 5)] [InlineData(true, 8, 8)] - [InlineData(false, 8, 4)] + [InlineData(false, 8, 4)] [InlineData(false, 16, 4)] // we always do 4 sub=pixels when antialising is off. public void MinimumAntialiasSubpixelDepth(bool antialias, int antialiasSubpixelDepth, int expectedAntialiasSubpixelDepth) { @@ -30,7 +30,7 @@ namespace ImageSharp.Tests.Drawing AntialiasSubpixelDepth = 1 }; FillRegionProcessor processor = new FillRegionProcessor(brush.Object, region.Object, options); - Image img = new Image(1, 1); + Image img = new Image(1, 1); processor.Apply(img, bounds); region.Verify(x => x.Scan(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()), Times.Exactly(4)); diff --git a/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs b/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs index 4a3c8e305..dc0b83615 100644 --- a/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs @@ -22,7 +22,7 @@ namespace ImageSharp.Tests.Drawing public void ImageShouldBeFloodFilledWithColorOnDefaultBackground() { string path = this.CreateOutputDirectory("Fill", "SolidBrush"); - using (Image image = new Image(500, 500)) + using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/DefaultBack.png")) { @@ -44,7 +44,7 @@ namespace ImageSharp.Tests.Drawing public void ImageShouldBeFloodFilledWithColor() { string path = this.CreateOutputDirectory("Fill", "SolidBrush"); - using (Image image = new Image(500, 500)) + using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { @@ -67,7 +67,7 @@ namespace ImageSharp.Tests.Drawing public void ImageShouldBeFloodFilledWithColorOpacity() { string path = this.CreateOutputDirectory("Fill", "SolidBrush"); - using (Image image = new Image(500, 500)) + using (Image image = new Image(500, 500)) { Rgba32 color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150); diff --git a/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs index bded40f32..1f35a3788 100644 --- a/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs @@ -32,7 +32,7 @@ namespace ImageSharp.Tests.Drawing new Vector2(93, 85), new Vector2(65, 137))); - using (Image image = new Image(500, 500)) + using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { @@ -82,7 +82,7 @@ namespace ImageSharp.Tests.Drawing new Vector2(263, 25), new Vector2(235, 57))); - using (Image image = new Image(500, 500)) + using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/SimpleVanishHole.png")) { @@ -133,7 +133,7 @@ namespace ImageSharp.Tests.Drawing new Vector2(130, 40), new Vector2(65, 137))); - using (Image image = new Image(500, 500)) + using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/SimpleOverlapping.png")) { @@ -179,7 +179,7 @@ namespace ImageSharp.Tests.Drawing new Vector2(93, 85), new Vector2(65, 137))); - using (Image image = new Image(500, 500)) + using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Dashed.png")) { @@ -207,7 +207,7 @@ namespace ImageSharp.Tests.Drawing new Vector2(65, 137))); Rgba32 color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150); - using (Image image = new Image(500, 500)) + using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) { diff --git a/tests/ImageSharp.Tests/Drawing/LineTests.cs b/tests/ImageSharp.Tests/Drawing/LineTests.cs index 87bda30be..3396d89c5 100644 --- a/tests/ImageSharp.Tests/Drawing/LineTests.cs +++ b/tests/ImageSharp.Tests/Drawing/LineTests.cs @@ -21,7 +21,7 @@ namespace ImageSharp.Tests.Drawing public void ImageShouldBeOverlayedByPath() { string path = this.CreateOutputDirectory("Drawing", "Lines"); - using (Image image = new Image(500, 500)) + using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { @@ -51,7 +51,7 @@ namespace ImageSharp.Tests.Drawing public void ImageShouldBeOverlayedByPath_NoAntialias() { string path = this.CreateOutputDirectory("Drawing", "Lines"); - using (Image image = new Image(500, 500)) + using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Simple_noantialias.png")) { @@ -82,7 +82,7 @@ namespace ImageSharp.Tests.Drawing public void ImageShouldBeOverlayedByPathDashed() { string path = this.CreateOutputDirectory("Drawing", "Lines"); - using (Image image = new Image(500, 500)) + using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Dashed.png")) { @@ -103,7 +103,7 @@ namespace ImageSharp.Tests.Drawing public void ImageShouldBeOverlayedByPathDotted() { string path = this.CreateOutputDirectory("Drawing", "Lines"); - using (Image image = new Image(500, 500)) + using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Dot.png")) { @@ -124,7 +124,7 @@ namespace ImageSharp.Tests.Drawing public void ImageShouldBeOverlayedByPathDashDot() { string path = this.CreateOutputDirectory("Drawing", "Lines"); - using (Image image = new Image(500, 500)) + using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/DashDot.png")) { @@ -145,7 +145,7 @@ namespace ImageSharp.Tests.Drawing public void ImageShouldBeOverlayedByPathDashDotDot() { string path = this.CreateOutputDirectory("Drawing", "Lines"); - Image image = new Image(500, 500); + Image image = new Image(500, 500); using (FileStream output = File.OpenWrite($"{path}/DashDotDot.png")) { @@ -167,7 +167,7 @@ namespace ImageSharp.Tests.Drawing Rgba32 color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150); - Image image = new Image(500, 500); + Image image = new Image(500, 500); using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) @@ -200,7 +200,7 @@ namespace ImageSharp.Tests.Drawing { string path = this.CreateOutputDirectory("Drawing", "Lines"); - Image image = new Image(500, 500); + Image image = new Image(500, 500); using (FileStream output = File.OpenWrite($"{path}/Rectangle.png")) { diff --git a/tests/ImageSharp.Tests/Drawing/Paths/DrawBeziersTests.cs b/tests/ImageSharp.Tests/Drawing/Paths/DrawBeziersTests.cs index 008df9091..a9b2284e8 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/DrawBeziersTests.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/DrawBeziersTests.cs @@ -18,8 +18,8 @@ namespace ImageSharp.Tests.Drawing.Paths float thickness = 7.2f; GraphicsOptions noneDefault = new GraphicsOptions(); Rgba32 color = Rgba32.HotPink; - SolidBrush brush = Brushes.Solid(Rgba32.HotPink); - Pen pen = new Pen(Rgba32.Firebrick, 99.9f); + 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), diff --git a/tests/ImageSharp.Tests/Drawing/Paths/DrawLinesTests.cs b/tests/ImageSharp.Tests/Drawing/Paths/DrawLinesTests.cs index 221cf7f29..3b7ba303d 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/DrawLinesTests.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/DrawLinesTests.cs @@ -17,8 +17,8 @@ namespace ImageSharp.Tests.Drawing.Paths float thickness = 7.2f; GraphicsOptions noneDefault = new GraphicsOptions(); Rgba32 color = Rgba32.HotPink; - SolidBrush brush = Brushes.Solid(Rgba32.HotPink); - Pen pen = new Pen(Rgba32.Gray, 99.9f); + 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), diff --git a/tests/ImageSharp.Tests/Drawing/Paths/DrawPath.cs b/tests/ImageSharp.Tests/Drawing/Paths/DrawPath.cs index 07be85b85..0bdcbdc08 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/DrawPath.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/DrawPath.cs @@ -18,8 +18,8 @@ namespace ImageSharp.Tests.Drawing.Paths float thickness = 7.2f; GraphicsOptions noneDefault = new GraphicsOptions(); Rgba32 color = Rgba32.HotPink; - SolidBrush brush = Brushes.Solid(Rgba32.HotPink); - Pen pen = new Pen(Rgba32.Gray, 99.9f); + 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), @@ -50,7 +50,7 @@ namespace ImageSharp.Tests.Drawing.Paths ShapePath shapepath = Assert.IsType(processor.Path); Assert.Equal(path, shapepath.Path); - + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(brush, pen.Brush); Assert.Equal(thickness, pen.Width); diff --git a/tests/ImageSharp.Tests/Drawing/Paths/DrawPolygon.cs b/tests/ImageSharp.Tests/Drawing/Paths/DrawPolygon.cs index bd90a460d..3474e6f62 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/DrawPolygon.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/DrawPolygon.cs @@ -18,8 +18,8 @@ namespace ImageSharp.Tests.Drawing.Paths float thickness = 7.2f; GraphicsOptions noneDefault = new GraphicsOptions(); Rgba32 color = Rgba32.HotPink; - SolidBrush brush = Brushes.Solid(Rgba32.HotPink); - Pen pen = new Pen(Rgba32.Gray, 99.9f); + 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), diff --git a/tests/ImageSharp.Tests/Drawing/Paths/DrawRectangle.cs b/tests/ImageSharp.Tests/Drawing/Paths/DrawRectangle.cs index 7ebc6b14f..e08e702c1 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/DrawRectangle.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/DrawRectangle.cs @@ -15,8 +15,8 @@ namespace ImageSharp.Tests.Drawing.Paths float thickness = 7.2f; GraphicsOptions noneDefault = new GraphicsOptions(); Rgba32 color = Rgba32.HotPink; - SolidBrush brush = Brushes.Solid(Rgba32.HotPink); - Pen pen = new Pen(Rgba32.Gray, 99.9f); + 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; diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs index a639a70cf..eb0127cb1 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs @@ -15,7 +15,7 @@ namespace ImageSharp.Tests.Drawing.Paths { GraphicsOptions noneDefault = new GraphicsOptions(); Rgba32 color = Rgba32.HotPink; - SolidBrush brush = Brushes.Solid(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), @@ -45,7 +45,7 @@ namespace ImageSharp.Tests.Drawing.Paths Assert.Equal(GraphicsOptions.Default, processor.Options); ShapeRegion region = Assert.IsType(processor.Region); - + // path is converted to a polygon before filling Polygon polygon = Assert.IsType(region.Shape); LinearLineSegment segments = Assert.IsType(polygon.LineSegments[0]); diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs index 2935c43a0..3f912fe79 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs @@ -15,7 +15,7 @@ namespace ImageSharp.Tests.Drawing.Paths { GraphicsOptions noneDefault = new GraphicsOptions(); Rgba32 color = Rgba32.HotPink; - SolidBrush brush = Brushes.Solid(Rgba32.HotPink); + SolidBrush brush = Brushes.Solid(Rgba32.HotPink); Vector2[] path = new Vector2[] { new Vector2(10,10), new Vector2(20,10), @@ -47,7 +47,7 @@ namespace ImageSharp.Tests.Drawing.Paths ShapeRegion region = Assert.IsType(processor.Region); Polygon polygon = Assert.IsType(region.Shape); LinearLineSegment segemnt = Assert.IsType(polygon.LineSegments[0]); - + Assert.Equal(brush, processor.Brush); } @@ -72,7 +72,7 @@ namespace ImageSharp.Tests.Drawing.Paths public void CorrectlySetsColorAndPath() { img.FillPolygon(color, path); - + Assert.NotEmpty(img.ProcessorApplications); FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs index 4657db988..1f4774550 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs @@ -14,7 +14,7 @@ namespace ImageSharp.Tests.Drawing.Paths { GraphicsOptions noneDefault = new GraphicsOptions(); Rgba32 color = Rgba32.HotPink; - SolidBrush brush = Brushes.Solid(Rgba32.HotPink); + SolidBrush brush = Brushes.Solid(Rgba32.HotPink); ImageSharp.Rectangle rectangle = new ImageSharp.Rectangle(10, 10, 77, 76); private ProcessorWatchingImage img; @@ -45,7 +45,7 @@ namespace ImageSharp.Tests.Drawing.Paths Assert.Equal(rect.Location.Y, rectangle.Y); Assert.Equal(rect.Size.Width, rectangle.Width); Assert.Equal(rect.Size.Height, rectangle.Height); - + Assert.Equal(brush, processor.Brush); } @@ -73,7 +73,7 @@ namespace ImageSharp.Tests.Drawing.Paths public void CorrectlySetsColorAndRectangle() { img.Fill(color, rectangle); - + Assert.NotEmpty(img.ProcessorApplications); FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); diff --git a/tests/ImageSharp.Tests/Drawing/Paths/ProcessorWatchingImage.cs b/tests/ImageSharp.Tests/Drawing/Paths/ProcessorWatchingImage.cs index d961a5994..c1d34a112 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/ProcessorWatchingImage.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/ProcessorWatchingImage.cs @@ -17,7 +17,7 @@ namespace ImageSharp.Tests.Drawing.Paths public List ProcessorApplications { get; } = new List(); public ProcessorWatchingImage(int width, int height) - : base(width, height, Configuration.CreateDefaultInstance()) + : base(Configuration.CreateDefaultInstance(), width, height) { } diff --git a/tests/ImageSharp.Tests/Drawing/PolygonTests.cs b/tests/ImageSharp.Tests/Drawing/PolygonTests.cs index 554c5a32e..9bc918d37 100644 --- a/tests/ImageSharp.Tests/Drawing/PolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/PolygonTests.cs @@ -22,7 +22,7 @@ namespace ImageSharp.Tests.Drawing { string path = this.CreateOutputDirectory("Drawing", "Polygons"); - using (Image image = new Image(500, 500)) + using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { @@ -62,7 +62,7 @@ namespace ImageSharp.Tests.Drawing Rgba32 color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150); - using (Image image = new Image(500, 500)) + using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) { @@ -93,7 +93,7 @@ namespace ImageSharp.Tests.Drawing { string path = this.CreateOutputDirectory("Drawing", "Polygons"); - using (Image image = new Image(500, 500)) + using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Rectangle.png")) { diff --git a/tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs b/tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs index d3236ae00..83419caaf 100644 --- a/tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs +++ b/tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs @@ -20,11 +20,11 @@ namespace ImageSharp.Tests { string path = this.CreateOutputDirectory("Drawing", "RecolorImage"); - RecolorBrush brush = new RecolorBrush(Rgba32.Yellow, Rgba32.HotPink, 0.2f); + RecolorBrush brush = new RecolorBrush(Rgba32.Yellow, Rgba32.HotPink, 0.2f); foreach (TestFile file in Files) { - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) { using (FileStream output = File.OpenWrite($"{path}/{file.FileName}")) { @@ -40,11 +40,11 @@ namespace ImageSharp.Tests { string path = this.CreateOutputDirectory("Drawing", "RecolorImage"); - RecolorBrush brush = new RecolorBrush(Rgba32.Yellow, Rgba32.HotPink, 0.2f); + RecolorBrush brush = new RecolorBrush(Rgba32.Yellow, Rgba32.HotPink, 0.2f); foreach (TestFile file in Files) { - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) { using (FileStream output = File.OpenWrite($"{path}/Shaped_{file.FileName}")) { diff --git a/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs b/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs index 0886aa15a..6cab7778e 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs @@ -26,7 +26,7 @@ namespace ImageSharp.Tests.Drawing new Vector2(240, 30), new Vector2(300, 400) }; - using (Image image = new Image(500, 500)) + using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { @@ -61,7 +61,7 @@ namespace ImageSharp.Tests.Drawing }; Rgba32 color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150); - using (Image image = new Image(500, 500)) + using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) { diff --git a/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs index 1de7e2144..5e0244d02 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs @@ -32,7 +32,7 @@ namespace ImageSharp.Tests.Drawing new Vector2(65, 137))); IPath clipped = simplePath.Clip(hole1); // var clipped = new Rectangle(10, 10, 100, 100).Clip(new Rectangle(20, 0, 20, 20)); - using (Image image = new Image(500, 500)) + using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { @@ -67,7 +67,7 @@ namespace ImageSharp.Tests.Drawing new Vector2(130, 40), new Vector2(65, 137))); - using (Image image = new Image(500, 500)) + using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/SimpleOverlapping.png")) { @@ -102,7 +102,7 @@ namespace ImageSharp.Tests.Drawing new Vector2(65, 137))); Rgba32 color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150); - using (Image image = new Image(500, 500)) + using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) { diff --git a/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs index d76dcf023..8ffa62d81 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs @@ -29,7 +29,7 @@ namespace ImageSharp.Tests.Drawing new Vector2(50, 300) }; - using (Image image = new Image(500, 500)) + using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { @@ -55,7 +55,7 @@ namespace ImageSharp.Tests.Drawing new Vector2(50, 300) }; - using (Image image = new Image(500, 500)) + using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Pattern.png")) { @@ -81,7 +81,7 @@ namespace ImageSharp.Tests.Drawing new Vector2(50, 300) }; - using (Image image = new Image(500, 500)) + using (Image image = new Image(500, 500)) using (FileStream output = File.OpenWrite($"{path}/Simple_NoAntialias.png")) { image @@ -112,11 +112,11 @@ namespace ImageSharp.Tests.Drawing new Vector2(50, 300) }; - using (Image brushImage = TestFile.Create(TestImages.Bmp.Car).CreateImage()) - using (Image image = new Image(500, 500)) + using (Image brushImage = TestFile.Create(TestImages.Bmp.Car).CreateImage()) + using (Image image = new Image(500, 500)) using (FileStream output = File.OpenWrite($"{path}/Image.png")) { - ImageBrush brush = new ImageBrush(brushImage); + ImageBrush brush = new ImageBrush(brushImage); image .BackgroundColor(Rgba32.Blue) @@ -136,7 +136,7 @@ namespace ImageSharp.Tests.Drawing }; Rgba32 color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150); - using (Image image = new Image(500, 500)) + using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) { @@ -161,7 +161,7 @@ namespace ImageSharp.Tests.Drawing { string path = this.CreateOutputDirectory("Drawing", "FilledPolygons"); - using (Image image = new Image(500, 500)) + using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Rectangle.png")) { @@ -191,7 +191,7 @@ namespace ImageSharp.Tests.Drawing { string path = this.CreateOutputDirectory("Drawing", "FilledPolygons"); - using (Image image = new Image(100, 100)) + using (Image image = new Image(100, 100)) { using (FileStream output = File.OpenWrite($"{path}/Triangle.png")) { @@ -217,7 +217,7 @@ namespace ImageSharp.Tests.Drawing Configuration config = Configuration.CreateDefaultInstance(); config.ParallelOptions.MaxDegreeOfParallelism = 1; - using (Image image = new Image(100, 100, config)) + using (Image image = new Image(config, 100, 100)) { using (FileStream output = File.OpenWrite($"{path}/Septagon.png")) { @@ -236,7 +236,7 @@ namespace ImageSharp.Tests.Drawing Configuration config = Configuration.CreateDefaultInstance(); config.ParallelOptions.MaxDegreeOfParallelism = 1; - using (Image image = new Image(100, 100, config)) + using (Image image = new Image(config, 100, 100)) { using (FileStream output = File.OpenWrite($"{path}/ellipse.png")) { @@ -256,7 +256,7 @@ namespace ImageSharp.Tests.Drawing Configuration config = Configuration.CreateDefaultInstance(); config.ParallelOptions.MaxDegreeOfParallelism = 1; - using (Image image = new Image(200, 200, config)) + using (Image image = new Image(config, 200, 200)) { using (FileStream output = File.OpenWrite($"{path}/clipped-corner.png")) { diff --git a/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs b/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs index bce493a69..1516b33d4 100644 --- a/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs +++ b/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs @@ -24,7 +24,7 @@ namespace ImageSharp.Tests.Drawing.Text { Rgba32 color = Rgba32.HotPink; - SolidBrush brush = Brushes.Solid(Rgba32.HotPink); + SolidBrush brush = Brushes.Solid(Rgba32.HotPink); IPath path = new SixLabors.Shapes.Path( new LinearLineSegment( diff --git a/tests/ImageSharp.Tests/Drawing/Text/OutputText.cs b/tests/ImageSharp.Tests/Drawing/Text/OutputText.cs index 1dbc93b9b..bb9cd264e 100644 --- a/tests/ImageSharp.Tests/Drawing/Text/OutputText.cs +++ b/tests/ImageSharp.Tests/Drawing/Text/OutputText.cs @@ -32,7 +32,7 @@ namespace ImageSharp.Tests.Drawing.Text public void DrawAB() { //draws 2 overlapping triangle glyphs twice 1 set on each line - using (Image img = new Image(100, 200)) + using (Image img = new Image(100, 200)) { img.Fill(Rgba32.DarkBlue) .DrawText("AB\nAB", new Font(this.Font, 50), Rgba32.Red, new Vector2(0, 0)); diff --git a/tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs index 497abb7d5..cf073d3d0 100644 --- a/tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs @@ -7,6 +7,8 @@ using ImageSharp.Formats; namespace ImageSharp.Tests { + using ImageSharp.PixelFormats; + using Xunit; public class BmpEncoderTests : FileTestBase @@ -27,7 +29,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileNameWithoutExtension(bitsPerPixel); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) { image.Save($"{path}/{filename}.bmp", new BmpEncoderOptions { BitsPerPixel = bitsPerPixel }); } diff --git a/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs b/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs index 1ecd04690..b47df8395 100644 --- a/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs +++ b/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs @@ -7,6 +7,8 @@ namespace ImageSharp.Tests { using System.IO; + using ImageSharp.PixelFormats; + using Xunit; public class GeneralFormatTests : FileTestBase @@ -18,7 +20,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) { using (FileStream output = File.OpenWrite($"{path}/{file.FileName}")) { @@ -37,7 +39,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) { string filename = path + "/" + file.FileNameWithoutExtension + ".txt"; File.WriteAllText(filename, image.ToBase64String()); @@ -52,7 +54,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) { using (FileStream output = File.OpenWrite($"{path}/{file.FileName}")) { @@ -69,9 +71,9 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { - using (Image srcImage = file.CreateImage()) + using (Image srcImage = file.CreateImage()) { - using (Image image = new Image(srcImage)) + using (Image image = new Image(srcImage)) { using (FileStream output = File.OpenWrite($"{path}/Octree-{file.FileName}")) { @@ -81,7 +83,7 @@ namespace ImageSharp.Tests } } - using (Image image = new Image(srcImage)) + using (Image image = new Image(srcImage)) { using (FileStream output = File.OpenWrite($"{path}/Wu-{file.FileName}")) { @@ -90,7 +92,7 @@ namespace ImageSharp.Tests } } - using (Image image = new Image(srcImage)) + using (Image image = new Image(srcImage)) { using (FileStream output = File.OpenWrite($"{path}/Palette-{file.FileName}")) { @@ -109,7 +111,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) { using (FileStream output = File.OpenWrite($"{path}/{file.FileNameWithoutExtension}.bmp")) { @@ -142,7 +144,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { byte[] serialized; - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (MemoryStream memoryStream = new MemoryStream()) { image.Save(memoryStream); @@ -150,7 +152,7 @@ namespace ImageSharp.Tests serialized = memoryStream.ToArray(); } - using (Image image2 = Image.Load(serialized)) + using (Image image2 = Image.Load(serialized)) using (FileStream output = File.OpenWrite($"{path}/{file.FileName}")) { image2.Save(output); diff --git a/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs index dd3019029..a5fc92901 100644 --- a/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs @@ -40,7 +40,7 @@ namespace ImageSharp.Tests TestFile testFile = TestFile.Create(TestImages.Gif.Rings); - using (Image image = testFile.CreateImage(options)) + using (Image image = testFile.CreateImage(options)) { Assert.Equal(1, image.MetaData.Properties.Count); Assert.Equal("Comments", image.MetaData.Properties[0].Name); @@ -58,7 +58,7 @@ namespace ImageSharp.Tests TestFile testFile = TestFile.Create(TestImages.Gif.Rings); - using (Image image = testFile.CreateImage(options)) + using (Image image = testFile.CreateImage(options)) { Assert.Equal(0, image.MetaData.Properties.Count); } @@ -74,7 +74,7 @@ namespace ImageSharp.Tests TestFile testFile = TestFile.Create(TestImages.Gif.Rings); - using (Image image = testFile.CreateImage(options)) + using (Image image = testFile.CreateImage(options)) { Assert.Equal(1, image.MetaData.Properties.Count); Assert.Equal("浉条卥慨灲", image.MetaData.Properties[0].Value); diff --git a/tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs index c657cde96..b0ffaaf85 100644 --- a/tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs @@ -36,14 +36,14 @@ namespace ImageSharp.Tests TestFile testFile = TestFile.Create(TestImages.Gif.Rings); - using (Image input = testFile.CreateImage()) + using (Image input = testFile.CreateImage()) { using (MemoryStream memStream = new MemoryStream()) { input.Save(memStream, new GifFormat(), options); memStream.Position = 0; - using (Image output = Image.Load(memStream)) + using (Image output = Image.Load(memStream)) { Assert.Equal(1, output.MetaData.Properties.Count); Assert.Equal("Comments", output.MetaData.Properties[0].Name); @@ -63,14 +63,14 @@ namespace ImageSharp.Tests TestFile testFile = TestFile.Create(TestImages.Gif.Rings); - using (Image input = testFile.CreateImage()) + using (Image input = testFile.CreateImage()) { using (MemoryStream memStream = new MemoryStream()) { input.SaveAsGif(memStream, options); memStream.Position = 0; - using (Image output = Image.Load(memStream)) + using (Image output = Image.Load(memStream)) { Assert.Equal(0, output.MetaData.Properties.Count); } @@ -81,7 +81,7 @@ namespace ImageSharp.Tests [Fact] public void Encode_CommentIsToLong_CommentIsTrimmed() { - using (Image input = new Image(1, 1)) + using (Image input = new Image(1, 1)) { string comments = new string('c', 256); input.MetaData.Properties.Add(new ImageProperty("Comments", comments)); @@ -91,7 +91,7 @@ namespace ImageSharp.Tests input.Save(memStream, new GifFormat()); memStream.Position = 0; - using (Image output = Image.Load(memStream)) + using (Image output = Image.Load(memStream)) { Assert.Equal(1, output.MetaData.Properties.Count); Assert.Equal("Comments", output.MetaData.Properties[0].Name); diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs index 1bcc72c43..a6d6d31f3 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs @@ -105,7 +105,7 @@ namespace ImageSharp.Tests [Fact] public void Decoder_Reads_Correct_Resolution_From_Jfif() { - using (Image image = TestFile.Create(TestImages.Jpeg.Baseline.Floorplan).CreateImage()) + using (Image image = TestFile.Create(TestImages.Jpeg.Baseline.Floorplan).CreateImage()) { Assert.Equal(300, image.MetaData.HorizontalResolution); Assert.Equal(300, image.MetaData.VerticalResolution); @@ -115,7 +115,7 @@ namespace ImageSharp.Tests [Fact] public void Decoder_Reads_Correct_Resolution_From_Exif() { - using (Image image = TestFile.Create(TestImages.Jpeg.Baseline.Jpeg420).CreateImage()) + using (Image image = TestFile.Create(TestImages.Jpeg.Baseline.Jpeg420).CreateImage()) { Assert.Equal(72, image.MetaData.HorizontalResolution); Assert.Equal(72, image.MetaData.VerticalResolution); @@ -132,7 +132,7 @@ namespace ImageSharp.Tests TestFile testFile = TestFile.Create(TestImages.Jpeg.Baseline.Floorplan); - using (Image image = testFile.CreateImage(options)) + using (Image image = testFile.CreateImage(options)) { Assert.NotNull(image.MetaData.ExifProfile); } @@ -148,7 +148,7 @@ namespace ImageSharp.Tests TestFile testFile = TestFile.Create(TestImages.Jpeg.Baseline.Floorplan); - using (Image image = testFile.CreateImage(options)) + using (Image image = testFile.CreateImage(options)) { Assert.Null(image.MetaData.ExifProfile); } diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs index d5f7c2ea3..1b4f3ea78 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs @@ -82,14 +82,14 @@ namespace ImageSharp.Tests TestFile testFile = TestFile.Create(TestImages.Jpeg.Baseline.Floorplan); - using (Image input = testFile.CreateImage()) + using (Image input = testFile.CreateImage()) { using (MemoryStream memStream = new MemoryStream()) { input.Save(memStream, new JpegFormat(), options); memStream.Position = 0; - using (Image output = Image.Load(memStream)) + using (Image output = Image.Load(memStream)) { Assert.NotNull(output.MetaData.ExifProfile); } @@ -107,14 +107,14 @@ namespace ImageSharp.Tests TestFile testFile = TestFile.Create(TestImages.Jpeg.Baseline.Floorplan); - using (Image input = testFile.CreateImage()) + using (Image input = testFile.CreateImage()) { using (MemoryStream memStream = new MemoryStream()) { input.SaveAsJpeg(memStream, options); memStream.Position = 0; - using (Image output = Image.Load(memStream)) + using (Image output = Image.Load(memStream)) { Assert.Null(output.MetaData.ExifProfile); } diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs index 5150925b4..b41826e2f 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs @@ -51,7 +51,7 @@ namespace ImageSharp.Tests ExecutionCount, () => { - Image img = Image.Load(bytes); + Image img = Image.Load(bytes); }, // ReSharper disable once ExplicitCallerInfoArgument $"Decode {fileName}"); diff --git a/tests/ImageSharp.Tests/Formats/Jpg/YCbCrImageTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/YCbCrImageTests.cs index ee38f500b..ba55665ca 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/YCbCrImageTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/YCbCrImageTests.cs @@ -61,9 +61,9 @@ namespace ImageSharp.Tests //this.PrintChannel("Cb", img.CbChannel); //this.PrintChannel("Cr", img.CrChannel); - Assert.Equal(img.YChannel.Stride, 400); - Assert.Equal(img.CbChannel.Stride, 400 / expectedCStrideDiv); - Assert.Equal(img.CrChannel.Stride, 400 / expectedCStrideDiv); + Assert.Equal(img.YChannel.Width, 400); + Assert.Equal(img.CbChannel.Width, 400 / expectedCStrideDiv); + Assert.Equal(img.CrChannel.Width, 400 / expectedCStrideDiv); } } diff --git a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs index d97b258dd..cf5c1cfa9 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs @@ -42,7 +42,7 @@ namespace ImageSharp.Tests TestFile testFile = TestFile.Create(TestImages.Png.Blur); - using (Image image = testFile.CreateImage(options)) + using (Image image = testFile.CreateImage(options)) { Assert.Equal(1, image.MetaData.Properties.Count); Assert.Equal("Software", image.MetaData.Properties[0].Name); @@ -60,7 +60,7 @@ namespace ImageSharp.Tests TestFile testFile = TestFile.Create(TestImages.Png.Blur); - using (Image image = testFile.CreateImage(options)) + using (Image image = testFile.CreateImage(options)) { Assert.Equal(0, image.MetaData.Properties.Count); } @@ -76,7 +76,7 @@ namespace ImageSharp.Tests TestFile testFile = TestFile.Create(TestImages.Png.Blur); - using (Image image = testFile.CreateImage(options)) + using (Image image = testFile.CreateImage(options)) { Assert.Equal(1, image.MetaData.Properties.Count); Assert.Equal("潓瑦慷敲", image.MetaData.Properties[0].Name); diff --git a/tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs index be965160c..22bb0b244 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs @@ -32,7 +32,7 @@ namespace ImageSharp.Tests.Formats.Png image.Save(ms, new PngEncoder()); ms.Position = 0; - using (Image img2 = Image.Load(ms, new PngDecoder())) + using (Image img2 = Image.Load(ms, new PngDecoder())) { // img2.Save(provider.Utility.GetTestOutputFileName("bmp", "_loaded"), new BmpEncoder()); ImageComparer.CheckSimilarity(image, img2); @@ -53,7 +53,7 @@ namespace ImageSharp.Tests.Formats.Png image.MetaData.Quality = 256; image.Save(ms, new PngEncoder()); ms.Position = 0; - using (Image img2 = Image.Load(ms, new PngDecoder())) + using (Image img2 = Image.Load(ms, new PngDecoder())) { // img2.Save(provider.Utility.GetTestOutputFileName("bmp", "_loaded"), new BmpEncoder()); ImageComparer.CheckSimilarity(image, img2, 0.03f); @@ -119,7 +119,7 @@ namespace ImageSharp.Tests.Formats.Png image.Save(ms, new PngEncoder()); ms.Position = 0; - using (Image img2 = Image.Load(ms, new PngDecoder())) + using (Image img2 = Image.Load(ms, new PngDecoder())) { ImageComparer.CheckSimilarity(image, img2); } diff --git a/tests/ImageSharp.Tests/Image/ImageLoadTests.cs b/tests/ImageSharp.Tests/Image/ImageLoadTests.cs index 505074a6a..4cdf529e6 100644 --- a/tests/ImageSharp.Tests/Image/ImageLoadTests.cs +++ b/tests/ImageSharp.Tests/Image/ImageLoadTests.cs @@ -33,8 +33,8 @@ namespace ImageSharp.Tests public ImageLoadTests() { - this.returnImage = new Image(1, 1); - + this.returnImage = new Image(1, 1); + this.localDecoder = new Mock(); this.localFormat = new Mock(); this.localFormat.Setup(x => x.Decoder).Returns(this.localDecoder.Object); @@ -57,7 +57,7 @@ namespace ImageSharp.Tests .Returns(this.returnImage); this.fileSystem = new Mock(); - + this.LocalConfiguration = new Configuration(this.localFormat.Object) { FileSystem = this.fileSystem.Object @@ -77,7 +77,7 @@ namespace ImageSharp.Tests [Fact] public void LoadFromStream() { - Image img = Image.Load(this.DataStream); + Image img = Image.Load(this.DataStream); Assert.NotNull(img); Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat); @@ -91,7 +91,7 @@ namespace ImageSharp.Tests public void LoadFromNoneSeekableStream() { NoneSeekableStream stream = new NoneSeekableStream(this.DataStream); - Image img = Image.Load(stream); + Image img = Image.Load(stream); Assert.NotNull(img); Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat); @@ -117,7 +117,7 @@ namespace ImageSharp.Tests [Fact] public void LoadFromStreamWithOptions() { - Image img = Image.Load(this.DataStream, this.decoderOptions); + Image img = Image.Load(this.DataStream, this.decoderOptions); Assert.NotNull(img); Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat); @@ -143,7 +143,7 @@ namespace ImageSharp.Tests public void LoadFromStreamWithConfig() { Stream stream = new MemoryStream(); - Image img = Image.Load(this.LocalConfiguration, stream); + Image img = Image.Load(this.LocalConfiguration, stream); Assert.NotNull(img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); @@ -170,7 +170,7 @@ namespace ImageSharp.Tests public void LoadFromStreamWithConfigAndOptions() { 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.localFormat.Object, img.CurrentImageFormat); @@ -199,7 +199,7 @@ namespace ImageSharp.Tests public void LoadFromStreamWithDecoder() { Stream stream = new MemoryStream(); - Image img = Image.Load(stream, this.localDecoder.Object); + Image img = Image.Load(stream, this.localDecoder.Object); Assert.NotNull(img); this.localDecoder.Verify(x => x.Decode(Configuration.Default, stream, null)); @@ -220,7 +220,7 @@ namespace ImageSharp.Tests public void LoadFromStreamWithDecoderAndOptions() { 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); this.localDecoder.Verify(x => x.Decode(Configuration.Default, stream, this.decoderOptions)); @@ -240,7 +240,7 @@ namespace ImageSharp.Tests [Fact] public void LoadFromBytes() { - Image img = Image.Load(this.DataStream.ToArray()); + Image img = Image.Load(this.DataStream.ToArray()); Assert.NotNull(img); Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat); @@ -266,7 +266,7 @@ namespace ImageSharp.Tests [Fact] public void LoadFromBytesWithOptions() { - 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, img.CurrentImageFormat); @@ -291,7 +291,7 @@ namespace ImageSharp.Tests [Fact] public void LoadFromBytesWithConfig() { - Image img = Image.Load(this.LocalConfiguration, this.DataStream.ToArray()); + Image img = Image.Load(this.LocalConfiguration, this.DataStream.ToArray()); Assert.NotNull(img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); @@ -319,7 +319,7 @@ namespace ImageSharp.Tests [Fact] public void LoadFromBytesWithConfigAndOptions() { - 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.localFormat.Object, img.CurrentImageFormat); @@ -347,7 +347,7 @@ namespace ImageSharp.Tests [Fact] public void LoadFromBytesWithDecoder() { - Image img = Image.Load(this.DataStream.ToArray(), this.localDecoder.Object); + Image img = Image.Load(this.DataStream.ToArray(), this.localDecoder.Object); Assert.NotNull(img); this.localDecoder.Verify(x => x.Decode(Configuration.Default, It.IsAny(), null)); @@ -368,7 +368,7 @@ namespace ImageSharp.Tests [Fact] public void LoadFromBytesWithDecoderAndOptions() { - 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); this.localDecoder.Verify(x => x.Decode(Configuration.Default, It.IsAny(), this.decoderOptions)); @@ -389,7 +389,7 @@ namespace ImageSharp.Tests [Fact] public void LoadFromFile() { - Image img = Image.Load(this.DataStream); + Image img = Image.Load(this.DataStream); Assert.NotNull(img); Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat); @@ -415,7 +415,7 @@ namespace ImageSharp.Tests [Fact] public void LoadFromFileWithOptions() { - Image img = Image.Load(this.DataStream, this.decoderOptions); + Image img = Image.Load(this.DataStream, this.decoderOptions); Assert.NotNull(img); Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat); @@ -440,7 +440,7 @@ namespace ImageSharp.Tests [Fact] public void LoadFromFileWithConfig() { - Image img = Image.Load(this.LocalConfiguration, this.FilePath); + Image img = Image.Load(this.LocalConfiguration, this.FilePath); Assert.NotNull(img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); @@ -465,7 +465,7 @@ namespace ImageSharp.Tests [Fact] public void LoadFromFileWithConfigAndOptions() { - 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.localFormat.Object, img.CurrentImageFormat); @@ -491,7 +491,7 @@ namespace ImageSharp.Tests [Fact] public void LoadFromFileWithDecoder() { - Image img = Image.Load(this.FilePath, this.localDecoder.Object); + Image img = Image.Load(this.FilePath, this.localDecoder.Object); Assert.NotNull(img); this.localDecoder.Verify(x => x.Decode(Configuration.Default, this.DataStream, null)); @@ -510,7 +510,7 @@ namespace ImageSharp.Tests [Fact] public void LoadFromFileWithDecoderAndOptions() { - 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); this.localDecoder.Verify(x => x.Decode(Configuration.Default, this.DataStream, this.decoderOptions)); diff --git a/tests/ImageSharp.Tests/Image/ImageSaveTests.cs b/tests/ImageSharp.Tests/Image/ImageSaveTests.cs index 902bedb5e..9e9852cb2 100644 --- a/tests/ImageSharp.Tests/Image/ImageSaveTests.cs +++ b/tests/ImageSharp.Tests/Image/ImageSaveTests.cs @@ -20,7 +20,7 @@ namespace ImageSharp.Tests /// public class ImageSaveTests : IDisposable { - private readonly Image Image; + private readonly Image Image; private readonly Mock fileSystem; private readonly Mock format; private readonly Mock formatNotRegistered; @@ -49,9 +49,10 @@ namespace ImageSharp.Tests this.fileSystem = new Mock(); this.encoderOptions = new Mock().Object; - this.Image = new Image(1, 1, new Configuration(this.format.Object) { + this.Image = new Image(new Configuration(this.format.Object) + { FileSystem = this.fileSystem.Object - }); + }, 1, 1); } [Fact] @@ -71,7 +72,7 @@ namespace ImageSharp.Tests this.fileSystem.Setup(x => x.Create("path.jpg")).Returns(stream); this.Image.Save("path.jpg", this.encoderOptions); - + this.encoder.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); } @@ -126,7 +127,7 @@ namespace ImageSharp.Tests { Stream stream = new MemoryStream(); this.Image.Save(stream); - + this.encoder.Verify(x => x.Encode(this.Image, stream, null)); } diff --git a/tests/ImageSharp.Tests/Image/ImageTests.cs b/tests/ImageSharp.Tests/Image/ImageTests.cs index 02b0e5ad9..a3ec4cec2 100644 --- a/tests/ImageSharp.Tests/Image/ImageTests.cs +++ b/tests/ImageSharp.Tests/Image/ImageTests.cs @@ -8,6 +8,7 @@ namespace ImageSharp.Tests using System; using ImageSharp.Formats; + using ImageSharp.PixelFormats; using Xunit; @@ -21,11 +22,11 @@ namespace ImageSharp.Tests { Assert.Throws(() => { - Image.Load((byte[])null); + Image.Load((byte[])null); }); TestFile file = TestFile.Create(TestImages.Bmp.Car); - using (Image image = Image.Load(file.Bytes)) + using (Image image = Image.Load(file.Bytes)) { Assert.Equal(600, image.Width); Assert.Equal(450, image.Height); @@ -36,7 +37,7 @@ namespace ImageSharp.Tests public void ConstructorFileSystem() { TestFile file = TestFile.Create(TestImages.Bmp.Car); - using (Image image = Image.Load(file.FilePath)) + using (Image image = Image.Load(file.FilePath)) { Assert.Equal(600, image.Width); Assert.Equal(450, image.Height); @@ -49,7 +50,7 @@ namespace ImageSharp.Tests System.IO.FileNotFoundException ex = Assert.Throws( () => { - Image.Load(Guid.NewGuid().ToString()); + Image.Load(Guid.NewGuid().ToString()); }); } @@ -59,7 +60,7 @@ namespace ImageSharp.Tests ArgumentNullException ex = Assert.Throws( () => { - Image.Load((string) null); + Image.Load((string)null); }); } @@ -68,13 +69,13 @@ namespace ImageSharp.Tests { string file = TestFile.GetPath("../../TestOutput/Save_DetecedEncoding.png"); System.IO.DirectoryInfo dir = System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(file)); - using (Image image = new Image(10, 10)) + using (Image image = new Image(10, 10)) { image.Save(file); } TestFile c = TestFile.Create("../../TestOutput/Save_DetecedEncoding.png"); - using (Image img = c.CreateImage()) + using (Image img = c.CreateImage()) { Assert.IsType(img.CurrentImageFormat); } @@ -87,7 +88,7 @@ namespace ImageSharp.Tests InvalidOperationException ex = Assert.Throws( () => { - using (Image image = new Image(10, 10)) + using (Image image = new Image(10, 10)) { image.Save(file); } @@ -99,13 +100,13 @@ namespace ImageSharp.Tests { string file = TestFile.GetPath("../../TestOutput/Save_SetFormat.dat"); System.IO.DirectoryInfo dir = System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(file)); - using (Image image = new Image(10, 10)) + using (Image image = new Image(10, 10)) { image.Save(file, new PngFormat()); } TestFile c = TestFile.Create("../../TestOutput/Save_SetFormat.dat"); - using (Image img = c.CreateImage()) + using (Image img = c.CreateImage()) { Assert.IsType(img.CurrentImageFormat); } @@ -116,13 +117,13 @@ namespace ImageSharp.Tests { string file = TestFile.GetPath("../../TestOutput/Save_SetEncoding.dat"); System.IO.DirectoryInfo dir = System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(file)); - using (Image image = new Image(10, 10)) + using (Image image = new Image(10, 10)) { image.Save(file, new PngEncoder()); } TestFile c = TestFile.Create("../../TestOutput/Save_SetEncoding.dat"); - using (Image img = c.CreateImage()) + using (Image img = c.CreateImage()) { Assert.IsType(img.CurrentImageFormat); } diff --git a/tests/ImageSharp.Tests/ImageComparer.cs b/tests/ImageSharp.Tests/ImageComparer.cs index 9b8a51fde..d339dc83d 100644 --- a/tests/ImageSharp.Tests/ImageComparer.cs +++ b/tests/ImageSharp.Tests/ImageComparer.cs @@ -2,6 +2,7 @@ { using System; using ImageSharp; + using ImageSharp.Memory; using ImageSharp.PixelFormats; using Xunit; diff --git a/tests/ImageSharp.Tests/MetaData/ImageMetaDataTests.cs b/tests/ImageSharp.Tests/MetaData/ImageMetaDataTests.cs index 4ef9c57aa..bc64d613a 100644 --- a/tests/ImageSharp.Tests/MetaData/ImageMetaDataTests.cs +++ b/tests/ImageSharp.Tests/MetaData/ImageMetaDataTests.cs @@ -6,6 +6,8 @@ namespace ImageSharp.Tests { using ImageSharp.Formats; + using ImageSharp.PixelFormats; + using Xunit; /// @@ -81,7 +83,7 @@ namespace ImageSharp.Tests exifProfile.SetValue(ExifTag.XResolution, new Rational(200)); exifProfile.SetValue(ExifTag.YResolution, new Rational(300)); - Image image = new Image(1, 1); + Image image = new Image(1, 1); image.MetaData.ExifProfile = exifProfile; image.MetaData.HorizontalResolution = 400; image.MetaData.VerticalResolution = 500; diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs index 6a832859a..db22300fa 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs @@ -20,7 +20,7 @@ namespace ImageSharp.Tests [Fact] public void Constructor() { - Image image = TestFile.Create(TestImages.Jpeg.Baseline.Calliphora).CreateImage(); + Image image = TestFile.Create(TestImages.Jpeg.Baseline.Calliphora).CreateImage(); Assert.Null(image.MetaData.ExifProfile); @@ -70,13 +70,13 @@ namespace ImageSharp.Tests profile.SetValue(ExifTag.ExposureTime, new Rational(exposureTime)); - Image image = new Image(1, 1); + Image image = new Image(1, 1); image.MetaData.ExifProfile = profile; image.SaveAsJpeg(memStream); memStream.Position = 0; - image = Image.Load(memStream); + image = Image.Load(memStream); profile = image.MetaData.ExifProfile; Assert.NotNull(profile); @@ -94,7 +94,7 @@ namespace ImageSharp.Tests image.SaveAsJpeg(memStream); memStream.Position = 0; - image = Image.Load(memStream); + image = Image.Load(memStream); profile = image.MetaData.ExifProfile; Assert.NotNull(profile); @@ -107,7 +107,7 @@ namespace ImageSharp.Tests [Fact] public void ReadWriteInfinity() { - Image image = TestFile.Create(TestImages.Jpeg.Baseline.Floorplan).CreateImage(); + Image image = TestFile.Create(TestImages.Jpeg.Baseline.Floorplan).CreateImage(); image.MetaData.ExifProfile.SetValue(ExifTag.ExposureBiasValue, new SignedRational(double.PositiveInfinity)); image = WriteAndRead(image); @@ -135,7 +135,7 @@ namespace ImageSharp.Tests { Rational[] latitude = new Rational[] { new Rational(12.3), new Rational(4.56), new Rational(789.0) }; - Image image = TestFile.Create(TestImages.Jpeg.Baseline.Floorplan).CreateImage(); + Image image = TestFile.Create(TestImages.Jpeg.Baseline.Floorplan).CreateImage(); image.MetaData.ExifProfile.SetValue(ExifTag.Software, "ImageSharp"); ExifValue value = image.MetaData.ExifProfile.GetValue(ExifTag.Software); @@ -261,7 +261,7 @@ namespace ImageSharp.Tests junk.Append("I"); } - Image image = new Image(100, 100); + Image image = new Image(100, 100); image.MetaData.ExifProfile = new ExifProfile(); image.MetaData.ExifProfile.SetValue(ExifTag.ImageDescription, junk.ToString()); @@ -274,7 +274,7 @@ namespace ImageSharp.Tests [Fact] public void ExifTypeUndefined() { - Image image = TestFile.Create(TestImages.Jpeg.Baseline.Bad.ExifUndefType).CreateImage(); + Image image = TestFile.Create(TestImages.Jpeg.Baseline.Bad.ExifUndefType).CreateImage(); Assert.NotNull(image); ExifProfile profile = image.MetaData.ExifProfile; @@ -291,7 +291,7 @@ namespace ImageSharp.Tests private static ExifProfile GetExifProfile() { - Image image = TestFile.Create(TestImages.Jpeg.Baseline.Floorplan).CreateImage(); + Image image = TestFile.Create(TestImages.Jpeg.Baseline.Floorplan).CreateImage(); ExifProfile profile = image.MetaData.ExifProfile; Assert.NotNull(profile); @@ -299,7 +299,7 @@ namespace ImageSharp.Tests return profile; } - private static Image WriteAndRead(Image image) + private static Image WriteAndRead(Image image) { using (MemoryStream memStream = new MemoryStream()) { @@ -307,7 +307,7 @@ namespace ImageSharp.Tests image.Dispose(); memStream.Position = 0; - return Image.Load(memStream); + return Image.Load(memStream); } } diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifValueTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifValueTests.cs index 2014d08dc..a91eb310d 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifValueTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifValueTests.cs @@ -6,6 +6,9 @@ namespace ImageSharp.Tests { using System.Linq; + + using ImageSharp.PixelFormats; + using Xunit; public class ExifValueTests @@ -13,7 +16,7 @@ namespace ImageSharp.Tests private static ExifValue GetExifValue() { ExifProfile profile; - using (Image image = TestFile.Create(TestImages.Jpeg.Baseline.Floorplan).CreateImage()) + using (Image image = TestFile.Create(TestImages.Jpeg.Baseline.Floorplan).CreateImage()) { profile = image.MetaData.ExifProfile; } diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests_TPixel.cs b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests_TPixel.cs index 5fa1fccbc..8932f1ffe 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests_TPixel.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests_TPixel.cs @@ -16,10 +16,10 @@ namespace ImageSharp.Tests.PixelFormats.PixelBlenders public class PorterDuffFunctionsTests_TPixel { - private static BufferSpan AsSpan(T value) + private static Span AsSpan(T value) where T : struct { - return new BufferSpan(new[] { value }); + return new Span(new[] { value }); } public static TheoryData NormalBlendFunctionData = new TheoryData() { @@ -50,7 +50,7 @@ namespace ImageSharp.Tests.PixelFormats.PixelBlenders public void NormalBlendFunction_Blender_Bulk(TestPixel back, TestPixel source, float amount, TestPixel expected) where TPixel : struct, IPixel { - BufferSpan dest = new BufferSpan(new TPixel[1]); + Span dest = new Span(new TPixel[1]); new DefaultNormalPixelBlender().Blend(dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); VectorAssert.Equal(expected, dest[0], 2); } @@ -89,7 +89,7 @@ namespace ImageSharp.Tests.PixelFormats.PixelBlenders public void MultiplyFunction_Blender_Bulk(TestPixel back, TestPixel source, float amount, TestPixel expected) where TPixel : struct, IPixel { - BufferSpan dest = new BufferSpan(new TPixel[1]); + Span dest = new Span(new TPixel[1]); new DefaultMultiplyPixelBlender().Blend(dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); VectorAssert.Equal(expected, dest[0], 2); } @@ -128,7 +128,7 @@ namespace ImageSharp.Tests.PixelFormats.PixelBlenders public void AddFunction_Blender_Bulk(TestPixel back, TestPixel source, float amount, TestPixel expected) where TPixel : struct, IPixel { - BufferSpan dest = new BufferSpan(new TPixel[1]); + Span dest = new Span(new TPixel[1]); new DefaultAddPixelBlender().Blend(dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); VectorAssert.Equal(expected, dest[0], 2); } @@ -167,7 +167,7 @@ namespace ImageSharp.Tests.PixelFormats.PixelBlenders public void SubstractFunction_Blender_Bulk(TestPixel back, TestPixel source, float amount, TestPixel expected) where TPixel : struct, IPixel { - BufferSpan dest = new BufferSpan(new TPixel[1]); + Span dest = new Span(new TPixel[1]); new DefaultSubstractPixelBlender().Blend(dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); VectorAssert.Equal(expected, dest[0], 2); } @@ -206,7 +206,7 @@ namespace ImageSharp.Tests.PixelFormats.PixelBlenders public void ScreenFunction_Blender_Bulk(TestPixel back, TestPixel source, float amount, TestPixel expected) where TPixel : struct, IPixel { - BufferSpan dest = new BufferSpan(new TPixel[1]); + Span dest = new Span(new TPixel[1]); new DefaultScreenPixelBlender().Blend(dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); VectorAssert.Equal(expected, dest[0], 2); } @@ -245,7 +245,7 @@ namespace ImageSharp.Tests.PixelFormats.PixelBlenders public void DarkenFunction_Blender_Bulk(TestPixel back, TestPixel source, float amount, TestPixel expected) where TPixel : struct, IPixel { - BufferSpan dest = new BufferSpan(new TPixel[1]); + Span dest = new Span(new TPixel[1]); new DefaultDarkenPixelBlender().Blend(dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); VectorAssert.Equal(expected, dest[0], 2); } @@ -284,7 +284,7 @@ namespace ImageSharp.Tests.PixelFormats.PixelBlenders public void LightenFunction_Blender_Bulk(TestPixel back, TestPixel source, float amount, TestPixel expected) where TPixel : struct, IPixel { - BufferSpan dest = new BufferSpan(new TPixel[1]); + Span dest = new Span(new TPixel[1]); new DefaultLightenPixelBlender().Blend(dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); VectorAssert.Equal(expected, dest[0], 2); } @@ -323,7 +323,7 @@ namespace ImageSharp.Tests.PixelFormats.PixelBlenders public void OverlayFunction_Blender_Bulk(TestPixel back, TestPixel source, float amount, TestPixel expected) where TPixel : struct, IPixel { - BufferSpan dest = new BufferSpan(new TPixel[1]); + Span dest = new Span(new TPixel[1]); new DefaultOverlayPixelBlender().Blend(dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); VectorAssert.Equal(expected, dest[0], 2); } @@ -362,7 +362,7 @@ namespace ImageSharp.Tests.PixelFormats.PixelBlenders public void HardLightFunction_Blender_Bulk(TestPixel back, TestPixel source, float amount, TestPixel expected) where TPixel : struct, IPixel { - BufferSpan dest = new BufferSpan(new TPixel[1]); + Span dest = new Span(new TPixel[1]); new DefaultHardLightPixelBlender().Blend(dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); VectorAssert.Equal(expected, dest[0], 2); } diff --git a/tests/ImageSharp.Tests/Processors/Filters/AlphaTest.cs b/tests/ImageSharp.Tests/Processors/Filters/AlphaTest.cs index e1557abca..e40e3a205 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/AlphaTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/AlphaTest.cs @@ -7,6 +7,8 @@ namespace ImageSharp.Tests { using System.IO; + using ImageSharp.PixelFormats; + using Xunit; public class AlphaTest : FileTestBase @@ -27,7 +29,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(value); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.Alpha(value).Save(output); @@ -44,7 +46,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(value + "-InBox"); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.Alpha(value, new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output); diff --git a/tests/ImageSharp.Tests/Processors/Filters/AutoOrientTests.cs b/tests/ImageSharp.Tests/Processors/Filters/AutoOrientTests.cs index ef183480c..470e7150b 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/AutoOrientTests.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/AutoOrientTests.cs @@ -6,6 +6,9 @@ namespace ImageSharp.Tests { using System.IO; + + using ImageSharp.PixelFormats; + using Processing; using Xunit; @@ -33,7 +36,7 @@ namespace ImageSharp.Tests TestFile file = TestFile.Create(TestImages.Bmp.F); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) { image.MetaData.ExifProfile = new ExifProfile(); image.MetaData.ExifProfile.SetValue(ExifTag.Orientation, orientation); diff --git a/tests/ImageSharp.Tests/Processors/Filters/BackgroundColorTest.cs b/tests/ImageSharp.Tests/Processors/Filters/BackgroundColorTest.cs index 4bc39f8ab..d7ca78d1b 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/BackgroundColorTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/BackgroundColorTest.cs @@ -20,7 +20,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{file.FileName}")) { image.BackgroundColor(Rgba32.HotPink).Save(output); @@ -36,7 +36,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName("-InBox"); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.BackgroundColor(Rgba32.HotPink, new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output); diff --git a/tests/ImageSharp.Tests/Processors/Filters/BinaryThresholdTest.cs b/tests/ImageSharp.Tests/Processors/Filters/BinaryThresholdTest.cs index f36014542..4e5e8a82e 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/BinaryThresholdTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/BinaryThresholdTest.cs @@ -7,6 +7,8 @@ namespace ImageSharp.Tests { using System.IO; + using ImageSharp.PixelFormats; + using Xunit; public class BinaryThresholdTest : FileTestBase @@ -27,7 +29,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(value); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.BinaryThreshold(value).Save(output); @@ -44,7 +46,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(value + "-InBox"); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.BinaryThreshold(value, new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output); diff --git a/tests/ImageSharp.Tests/Processors/Filters/BlackWhiteTest.cs b/tests/ImageSharp.Tests/Processors/Filters/BlackWhiteTest.cs index 377ae4719..d10698a99 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/BlackWhiteTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/BlackWhiteTest.cs @@ -7,6 +7,8 @@ namespace ImageSharp.Tests { using System.IO; + using ImageSharp.PixelFormats; + using Xunit; public class BlackWhiteTest : FileTestBase @@ -18,7 +20,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{file.FileName}")) { image.BlackWhite().Save(output); @@ -34,7 +36,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName("-InBox"); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.BlackWhite(new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output); diff --git a/tests/ImageSharp.Tests/Processors/Filters/BoxBlurTest.cs b/tests/ImageSharp.Tests/Processors/Filters/BoxBlurTest.cs index f4f5fb4bb..03226a961 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/BoxBlurTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/BoxBlurTest.cs @@ -7,6 +7,8 @@ namespace ImageSharp.Tests { using System.IO; + using ImageSharp.PixelFormats; + using Xunit; public class BoxBlurTest : FileTestBase @@ -27,7 +29,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(value); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.BoxBlur(value).Save(output); @@ -44,7 +46,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(value + "-InBox"); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.BoxBlur(value, new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output); diff --git a/tests/ImageSharp.Tests/Processors/Filters/BrightnessTest.cs b/tests/ImageSharp.Tests/Processors/Filters/BrightnessTest.cs index f59d5be4c..ce434d734 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/BrightnessTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/BrightnessTest.cs @@ -7,6 +7,8 @@ namespace ImageSharp.Tests { using System.IO; + using ImageSharp.PixelFormats; + using Xunit; public class BrightnessTest : FileTestBase @@ -27,7 +29,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(value); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.Brightness(value).Save(output); @@ -44,7 +46,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(value + "-InBox"); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.Brightness(value, new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output); diff --git a/tests/ImageSharp.Tests/Processors/Filters/ColorBlindnessTest.cs b/tests/ImageSharp.Tests/Processors/Filters/ColorBlindnessTest.cs index 5564a77ef..c28732253 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/ColorBlindnessTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/ColorBlindnessTest.cs @@ -8,6 +8,8 @@ namespace ImageSharp.Tests using Processing; using System.IO; + using ImageSharp.PixelFormats; + using Xunit; public class ColorBlindnessTest : FileTestBase @@ -34,7 +36,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(colorBlindness); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.ColorBlindness(colorBlindness).Save(output); @@ -51,7 +53,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(colorBlindness + "-InBox"); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.ColorBlindness(colorBlindness, new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output); diff --git a/tests/ImageSharp.Tests/Processors/Filters/ContrastTest.cs b/tests/ImageSharp.Tests/Processors/Filters/ContrastTest.cs index 5bbe2338c..4626fbb6e 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/ContrastTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/ContrastTest.cs @@ -7,6 +7,8 @@ namespace ImageSharp.Tests { using System.IO; + using ImageSharp.PixelFormats; + using Xunit; public class ContrastTest : FileTestBase @@ -26,7 +28,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{file.FileName}")) { image.Contrast(value).Save(output); @@ -43,7 +45,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(value + "-InBox"); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.Contrast(value, new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output); diff --git a/tests/ImageSharp.Tests/Processors/Filters/CropTest.cs b/tests/ImageSharp.Tests/Processors/Filters/CropTest.cs index 69c9d9372..6713d0d38 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/CropTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/CropTest.cs @@ -7,6 +7,8 @@ namespace ImageSharp.Tests { using System.IO; + using ImageSharp.PixelFormats; + using Xunit; public class CropTest : FileTestBase @@ -18,7 +20,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{file.FileName}")) { image.Crop(image.Width / 2, image.Height / 2).Save(output); diff --git a/tests/ImageSharp.Tests/Processors/Filters/DetectEdgesTest.cs b/tests/ImageSharp.Tests/Processors/Filters/DetectEdgesTest.cs index e12440106..00440e8a5 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/DetectEdgesTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/DetectEdgesTest.cs @@ -8,6 +8,8 @@ namespace ImageSharp.Tests using Processing; using System.IO; + using ImageSharp.PixelFormats; + using Xunit; public class DetectEdgesTest : FileTestBase @@ -36,7 +38,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(detector); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.DetectEdges(detector).Save(output); @@ -53,7 +55,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(detector + "-InBox"); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.DetectEdges(detector, new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2)) diff --git a/tests/ImageSharp.Tests/Processors/Filters/DitherTest.cs b/tests/ImageSharp.Tests/Processors/Filters/DitherTest.cs index e89a1b1ec..066e2d134 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/DitherTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/DitherTest.cs @@ -9,6 +9,7 @@ namespace ImageSharp.Tests using ImageSharp.Dithering; using ImageSharp.Dithering.Ordered; + using ImageSharp.PixelFormats; using Xunit; @@ -41,7 +42,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(name); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.Dither(ditherer).Save(output); @@ -58,7 +59,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName($"{name}-InBox"); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.Dither(ditherer, new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output); @@ -75,7 +76,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(name); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.Dither(diffuser, .5F).Save(output); @@ -92,7 +93,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName($"{name}-InBox"); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.Dither(diffuser, .5F, new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output); diff --git a/tests/ImageSharp.Tests/Processors/Filters/EntropyCropTest.cs b/tests/ImageSharp.Tests/Processors/Filters/EntropyCropTest.cs index 1299d9814..710e23e37 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/EntropyCropTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/EntropyCropTest.cs @@ -7,6 +7,8 @@ namespace ImageSharp.Tests { using System.IO; + using ImageSharp.PixelFormats; + using Xunit; public class EntropyCropTest : FileTestBase @@ -27,7 +29,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(value); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.EntropyCrop(value).Save(output); diff --git a/tests/ImageSharp.Tests/Processors/Filters/FlipTests.cs b/tests/ImageSharp.Tests/Processors/Filters/FlipTests.cs index 26bc240d5..87f5e1025 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/FlipTests.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/FlipTests.cs @@ -6,6 +6,9 @@ namespace ImageSharp.Tests { using System.IO; + + using ImageSharp.PixelFormats; + using Processing; using Xunit; @@ -28,7 +31,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(flipType); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.Flip(flipType).Save(output); diff --git a/tests/ImageSharp.Tests/Processors/Filters/GlowTest.cs b/tests/ImageSharp.Tests/Processors/Filters/GlowTest.cs index ebbfdd5f0..43e45f9ca 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/GlowTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/GlowTest.cs @@ -20,7 +20,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{file.FileName}")) { image.Glow().Save(output); @@ -36,7 +36,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName("Color"); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.Glow(Rgba32.HotPink).Save(output); @@ -52,7 +52,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName("Radius"); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.Glow(image.Width / 4F).Save(output); @@ -68,7 +68,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName("InBox"); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.Glow(new Rectangle(image.Width / 8, image.Height / 8, image.Width / 2, image.Height / 2)) diff --git a/tests/ImageSharp.Tests/Processors/Filters/HueTest.cs b/tests/ImageSharp.Tests/Processors/Filters/HueTest.cs index 3081c638c..488433931 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/HueTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/HueTest.cs @@ -7,6 +7,8 @@ namespace ImageSharp.Tests { using System.IO; + using ImageSharp.PixelFormats; + using Xunit; public class HueTest : FileTestBase @@ -27,7 +29,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(value); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.Hue(value).Save(output); @@ -44,7 +46,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(value + "-InBox"); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.Hue(value, new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output); diff --git a/tests/ImageSharp.Tests/Processors/Filters/InvertTest.cs b/tests/ImageSharp.Tests/Processors/Filters/InvertTest.cs index da672f830..6d375d09a 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/InvertTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/InvertTest.cs @@ -7,6 +7,8 @@ namespace ImageSharp.Tests { using System.IO; + using ImageSharp.PixelFormats; + using Xunit; public class InvertTest : FileTestBase @@ -17,7 +19,7 @@ namespace ImageSharp.Tests string path = this.CreateOutputDirectory("Invert"); foreach (TestFile file in Files) { - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{file.FileName}")) { image.Invert().Save(output); @@ -33,7 +35,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName("InBox"); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.Invert(new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output); diff --git a/tests/ImageSharp.Tests/Processors/Filters/KodachromeTest.cs b/tests/ImageSharp.Tests/Processors/Filters/KodachromeTest.cs index 870f813a1..29a459f97 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/KodachromeTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/KodachromeTest.cs @@ -7,6 +7,8 @@ namespace ImageSharp.Tests { using System.IO; + using ImageSharp.PixelFormats; + using Xunit; public class KodachromeTest : FileTestBase @@ -18,7 +20,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{file.FileName}")) { image.Kodachrome().Save(output); @@ -34,7 +36,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName("InBox"); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.Kodachrome(new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output); diff --git a/tests/ImageSharp.Tests/Processors/Filters/LomographTest.cs b/tests/ImageSharp.Tests/Processors/Filters/LomographTest.cs index 57ca72d39..6ceedecbd 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/LomographTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/LomographTest.cs @@ -7,6 +7,8 @@ namespace ImageSharp.Tests { using System.IO; + using ImageSharp.PixelFormats; + using Xunit; public class LomographTest : FileTestBase @@ -18,7 +20,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{file.FileName}")) { image.Lomograph().Save(output); @@ -34,7 +36,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName("InBox"); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.Lomograph(new Rectangle(image.Width / 4, image.Width / 4, image.Width / 2, image.Height / 2)) diff --git a/tests/ImageSharp.Tests/Processors/Filters/OilPaintTest.cs b/tests/ImageSharp.Tests/Processors/Filters/OilPaintTest.cs index a9b552e21..5facee346 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/OilPaintTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/OilPaintTest.cs @@ -8,6 +8,8 @@ namespace ImageSharp.Tests using System; using System.IO; + using ImageSharp.PixelFormats; + using Xunit; public class OilPaintTest : FileTestBase @@ -28,7 +30,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(value); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { if (image.Width > value.Item2 && image.Height > value.Item2) @@ -48,7 +50,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(value + "-InBox"); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) { if (image.Width > value.Item2 && image.Height > value.Item2) { diff --git a/tests/ImageSharp.Tests/Processors/Filters/PadTest.cs b/tests/ImageSharp.Tests/Processors/Filters/PadTest.cs index f00cdd4f3..6095410a9 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/PadTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/PadTest.cs @@ -7,6 +7,8 @@ namespace ImageSharp.Tests { using System.IO; + using ImageSharp.PixelFormats; + using Xunit; public class PadTest : FileTestBase @@ -18,7 +20,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{file.FileName}")) { image.Pad(image.Width + 50, image.Height + 50).Save(output); diff --git a/tests/ImageSharp.Tests/Processors/Filters/PolaroidTest.cs b/tests/ImageSharp.Tests/Processors/Filters/PolaroidTest.cs index e9938fb83..df3803255 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/PolaroidTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/PolaroidTest.cs @@ -7,6 +7,8 @@ namespace ImageSharp.Tests { using System.IO; + using ImageSharp.PixelFormats; + using Xunit; public class PolaroidTest : FileTestBase @@ -18,7 +20,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{file.FileName}")) { image.Polaroid().Save(output); @@ -34,7 +36,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName("InBox"); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.Polaroid(new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output); diff --git a/tests/ImageSharp.Tests/Processors/Filters/ResizeProfilingBenchmarks.cs b/tests/ImageSharp.Tests/Processors/Filters/ResizeProfilingBenchmarks.cs index 917bb895c..a743665d4 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/ResizeProfilingBenchmarks.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/ResizeProfilingBenchmarks.cs @@ -27,7 +27,7 @@ namespace ImageSharp.Tests this.Measure(this.ExecutionCount, () => { - using (Image image = new Image(width, height)) + using (Image image = new Image(width, height)) { image.Resize(width / 4, height / 4); } diff --git a/tests/ImageSharp.Tests/Processors/Filters/ResizeTests.cs b/tests/ImageSharp.Tests/Processors/Filters/ResizeTests.cs index 643033f4c..31f4020b6 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/ResizeTests.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/ResizeTests.cs @@ -6,6 +6,9 @@ namespace ImageSharp.Tests { using System; using System.IO; + + using ImageSharp.PixelFormats; + using Processing; using Xunit; @@ -42,7 +45,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(name); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.Resize(image.Width / 2, image.Height / 2, sampler, true).Save(output); @@ -61,7 +64,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(name); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { Rectangle sourceRectangle = new Rectangle(image.Width / 8, image.Height / 8, image.Width / 4, image.Height / 4); @@ -82,7 +85,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(name); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.Resize(image.Width / 3, 0, sampler, false).Save(output); @@ -101,7 +104,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(name); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.Resize(0, image.Height / 3, sampler, false).Save(output); @@ -120,7 +123,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(name); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { ResizeOptions options = new ResizeOptions @@ -145,7 +148,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(name); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { ResizeOptions options = new ResizeOptions @@ -170,7 +173,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(name); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { ResizeOptions options = new ResizeOptions @@ -195,7 +198,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(name); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { ResizeOptions options = new ResizeOptions @@ -221,7 +224,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(name); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { ResizeOptions options = new ResizeOptions @@ -247,7 +250,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(name); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { ResizeOptions options = new ResizeOptions @@ -273,7 +276,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(name); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { ResizeOptions options = new ResizeOptions diff --git a/tests/ImageSharp.Tests/Processors/Filters/RotateFlipTest.cs b/tests/ImageSharp.Tests/Processors/Filters/RotateFlipTest.cs index e235ed229..c4c4fa8d7 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/RotateFlipTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/RotateFlipTest.cs @@ -6,6 +6,9 @@ namespace ImageSharp.Tests { using System.IO; + + using ImageSharp.PixelFormats; + using Processing; using Xunit; @@ -30,7 +33,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(rotateType + "-" + flipType); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.RotateFlip(rotateType, flipType).Save(output); diff --git a/tests/ImageSharp.Tests/Processors/Filters/RotateTest.cs b/tests/ImageSharp.Tests/Processors/Filters/RotateTest.cs index a504fd989..b30c795ad 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/RotateTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/RotateTest.cs @@ -6,6 +6,9 @@ namespace ImageSharp.Tests { using System.IO; + + using ImageSharp.PixelFormats; + using Processing; using Xunit; @@ -36,7 +39,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(value); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.Rotate(value).Save(output); @@ -53,7 +56,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(value); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.Rotate(value).Save(output); diff --git a/tests/ImageSharp.Tests/Processors/Filters/SaturationTest.cs b/tests/ImageSharp.Tests/Processors/Filters/SaturationTest.cs index ee24f120c..e28847fa3 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/SaturationTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/SaturationTest.cs @@ -7,6 +7,8 @@ namespace ImageSharp.Tests { using System.IO; + using ImageSharp.PixelFormats; + using Xunit; public class SaturationTest : FileTestBase @@ -27,7 +29,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(value); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.Saturation(value).Save(output); @@ -44,7 +46,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(value + "-InBox"); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.Saturation(value, new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output); diff --git a/tests/ImageSharp.Tests/Processors/Filters/SepiaTest.cs b/tests/ImageSharp.Tests/Processors/Filters/SepiaTest.cs index 0e1583cc6..490213ce7 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/SepiaTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/SepiaTest.cs @@ -7,6 +7,8 @@ namespace ImageSharp.Tests { using System.IO; + using ImageSharp.PixelFormats; + using Xunit; public class SepiaTest : FileTestBase @@ -18,7 +20,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{file.FileName}")) { image.Sepia().Save(output); @@ -34,7 +36,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName("InBox"); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.Sepia(new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output); diff --git a/tests/ImageSharp.Tests/Processors/Filters/SkewTest.cs b/tests/ImageSharp.Tests/Processors/Filters/SkewTest.cs index 231f5dae8..d096b3913 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/SkewTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/SkewTest.cs @@ -7,6 +7,8 @@ namespace ImageSharp.Tests { using System.IO; + using ImageSharp.PixelFormats; + using Xunit; public class SkewTest : FileTestBase @@ -29,7 +31,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName(x + "-" + y); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.Skew(x, y).Save(output); diff --git a/tests/ImageSharp.Tests/Processors/Filters/VignetteTest.cs b/tests/ImageSharp.Tests/Processors/Filters/VignetteTest.cs index 89794aeaf..4191ae8fa 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/VignetteTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/VignetteTest.cs @@ -20,7 +20,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{file.FileName}")) { image.Vignette().Save(output); @@ -36,7 +36,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName("Color"); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.Vignette(Rgba32.HotPink).Save(output); @@ -52,7 +52,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName("Radius"); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.Vignette(image.Width / 4F, image.Height / 4F).Save(output); @@ -68,7 +68,7 @@ namespace ImageSharp.Tests foreach (TestFile file in Files) { string filename = file.GetFileName("InBox"); - using (Image image = file.CreateImage()) + using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.Vignette(new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2)) diff --git a/tests/ImageSharp.Tests/TestFile.cs b/tests/ImageSharp.Tests/TestFile.cs index eedc0d306..f1b78383c 100644 --- a/tests/ImageSharp.Tests/TestFile.cs +++ b/tests/ImageSharp.Tests/TestFile.cs @@ -12,6 +12,8 @@ namespace ImageSharp.Tests using System.Linq; using System.Reflection; + using ImageSharp.PixelFormats; + /// /// A test image file. /// @@ -30,7 +32,7 @@ namespace ImageSharp.Tests /// /// The image. /// - private readonly Image image; + private readonly Image image; /// /// The file. @@ -46,7 +48,7 @@ namespace ImageSharp.Tests this.file = file; this.Bytes = File.ReadAllBytes(file); - this.image = Image.Load(this.Bytes); + this.image = Image.Load(this.Bytes); } /// @@ -125,9 +127,9 @@ namespace ImageSharp.Tests /// /// The . /// - public Image CreateImage() + public Image CreateImage() { - return new Image(this.image); + return new Image(this.image); } /// @@ -137,9 +139,9 @@ namespace ImageSharp.Tests /// /// The . /// - public Image CreateImage(IDecoderOptions options) + public Image CreateImage(IDecoderOptions options) { - return Image.Load(this.Bytes, options); + return Image.Load(this.Bytes, options); } /// diff --git a/tests/ImageSharp.Tests/TestUtilities/Factories/ImageFactory.cs b/tests/ImageSharp.Tests/TestUtilities/Factories/ImageFactory.cs index c4d758bd6..20af430a5 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Factories/ImageFactory.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Factories/ImageFactory.cs @@ -9,14 +9,13 @@ namespace ImageSharp.Tests 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) { - Image img = (Image)other; - return new Image(img); + return new Image(other); } } } diff --git a/tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs b/tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs index 77c13f125..f64b77271 100644 --- a/tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs +++ b/tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs @@ -53,7 +53,7 @@ namespace ImageSharp.Tests Short4 = 1 << 17, /// - /// Triggers instantiating the subclass of + /// Triggers instantiating the subclass of /// StandardImageClass = 1 << 29, diff --git a/tests/ImageSharp.Tests/TestUtilities/TestPixel.cs b/tests/ImageSharp.Tests/TestUtilities/TestPixel.cs index 7e3d318c0..852bc587d 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestPixel.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestPixel.cs @@ -38,9 +38,9 @@ namespace ImageSharp.Tests.TestUtilities return pix; } - internal BufferSpan AsSpan() + internal Span AsSpan() { - return new BufferSpan(new[] { AsPixel() }); + return new Span(new[] { AsPixel() }); } public void Deserialize(IXunitSerializationInfo info) diff --git a/tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs b/tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs index de05e83a9..dfaf1c052 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs @@ -25,26 +25,27 @@ namespace ImageSharp.Tests private static readonly Dictionary PixelTypes2ClrTypes = new Dictionary(); private static readonly PixelTypes[] AllConcretePixelTypes = GetAllPixelTypes() - .Except(new [] {PixelTypes.Undefined, PixelTypes.All }) + .Except(new[] { PixelTypes.Undefined, PixelTypes.All }) .ToArray(); static TestUtilityExtensions() { - 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)) + // Add Rgba32 Our default. + Type defaultPixelFormatType = typeof(Rgba32); + PixelTypes2ClrTypes[PixelTypes.Rgba32] = defaultPixelFormatType; + ClrTypes2PixelTypes[defaultPixelFormatType] = PixelTypes.Rgba32; + + // Add PixelFormat types + string nameSpace = typeof(Alpha8).FullName; + nameSpace = nameSpace.Substring(0, nameSpace.Length - typeof(Alpha8).Name.Length - 1); + foreach (PixelTypes pt in AllConcretePixelTypes.Where(pt => pt != PixelTypes.StandardImageClass && pt != PixelTypes.Rgba32)) { - string typeName = $"{nameSpace}.{pt.ToString()}"; + string typeName = $"{nameSpace}.{pt}"; Type t = ImageSharpAssembly.GetType(typeName); - if (t == null) - { - throw new InvalidOperationException($"Could not find: {typeName}"); - } - - PixelTypes2ClrTypes[pt] = t; + PixelTypes2ClrTypes[pt] = t ?? throw new InvalidOperationException($"Could not find: {typeName}"); ClrTypes2PixelTypes[t] = pt; } - PixelTypes2ClrTypes[PixelTypes.StandardImageClass] = typeof(Rgba32); + PixelTypes2ClrTypes[PixelTypes.StandardImageClass] = defaultPixelFormatType; } public static bool HasFlag(this PixelTypes pixelTypes, PixelTypes flag) => (pixelTypes & flag) == flag; diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs index 7d176c1e3..4d3a0d991 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs @@ -66,7 +66,7 @@ namespace ImageSharp.Tests { Image img = provider.GetImage(); - Assert.IsType(img); + Assert.IsType>(img); } [Theory] @@ -146,7 +146,7 @@ namespace ImageSharp.Tests Assert.Equal(img.Width, 3); if (provider.PixelType == PixelTypes.StandardImageClass) { - Assert.IsType(img); + Assert.IsType>(img); } } diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs index 29623e1b5..9ff0ca64e 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs @@ -53,13 +53,13 @@ namespace ImageSharp.Tests [Fact] public void Baz() { - Type type = typeof(Rgba32).GetTypeInfo().Assembly.GetType("ImageSharp.PixelFormats.Rgba32"); + Type type = typeof(Rgba32).GetTypeInfo().Assembly.GetType("ImageSharp.Rgba32"); this.Output.WriteLine(type.ToString()); Type fake = typeof(Rgba32).GetTypeInfo().Assembly.GetType("ImageSharp.dsaada_DASqewrr"); Assert.Null(fake); } - + [Theory] [WithFile(TestImages.Bmp.Car, PixelTypes.Rgba32, true)] [WithFile(TestImages.Bmp.Car, PixelTypes.Rgba32, false)] @@ -137,4 +137,4 @@ namespace ImageSharp.Tests AssertContainsPixelType(PixelTypes.StandardImageClass, expanded); } } -} \ No newline at end of file +}