diff --git a/ImageSharp.ruleset b/ImageSharp.ruleset index 2149364b1b..3567dc4b9e 100644 --- a/ImageSharp.ruleset +++ b/ImageSharp.ruleset @@ -7,5 +7,7 @@ temp remove the header requirement as stylecop is currently failing to read the stylecop.json file from 'dotnet build' --> + + \ No newline at end of file diff --git a/README.md b/README.md index d9d2628bb7..7e47e6b06f 100644 --- a/README.md +++ b/README.md @@ -4,31 +4,32 @@ ImageSharp

- GitHub license - Gitter - Twitter - OpenCollective - OpenCollective + GitHub license + Gitter + Twitter + OpenCollective + OpenCollective ### **ImageSharp** is a new, fully featured, fully managed, cross-platform, 2D graphics API. -Without the use of `System.Drawing` we have been able to develop something much more flexible, easier to code against, and much, much less prone to memory leaks. Gone are system-wide process-locks; ImageSharp images are thread-safe and fully supported in web environments. +Designed to democratize image processing, ImageSharp brings you an incredibly powerful yet beautifully simple API. -Built against .Net Standard 1.1 ImageSharp can be used in device, cloud, and embedded/IoT scenarios. - -### Questions? +Compared to `System.Drawing` we have been able to develop something much more flexible, easier to code against, and much, much less prone to memory leaks. Gone are system-wide process-locks; ImageSharp images are thread-safe and fully supported in web environments. -Do you have questions? We are happy to help! Please [join our gitter channel](https://gitter.im/ImageSharp/General), or ask them on [stackoverflow](https://stackoverflow.com) using the `ImageSharp` tag. +Built against .Net Standard 1.1 ImageSharp can be used in device, cloud, and embedded/IoT scenarios. ### Installation +Install stable releases via Nuget;evelopment releases are available via MyGet. + | Package Name | Release (NuGet) | Nightly (MyGet) | |--------------------------------|-----------------|-----------------| | `SixLabors.ImageSharp` | [![NuGet](https://img.shields.io/nuget/v/SixLabors.ImageSharp.svg)](https://www.nuget.org/packages/SixLabors.ImageSharp/) | [![MyGet](https://img.shields.io/myget/sixlabors/v/SixLabors.ImageSharp.svg)](https://www.myget.org/feed/sixlabors/package/nuget/SixLabors.ImageSharp) | | `SixLabors.ImageSharp.Drawing` | [![NuGet](https://img.shields.io/nuget/v/SixLabors.ImageSharp.Drawing.svg)](https://www.nuget.org/packages/SixLabors.ImageSharp.Drawing/) | [![MyGet](https://img.shields.io/myget/sixlabors/v/SixLabors.ImageSharp.Drawing.svg)](https://www.myget.org/feed/sixlabors/package/nuget/SixLabors.ImageSharp.Drawing) | ### Packages + The **ImageSharp** library is made up of multiple packages: - **SixLabors.ImageSharp** - Contains the generic `Image` class, PixelFormats, Primitives, Configuration, and other core functionality. @@ -48,31 +49,37 @@ The **ImageSharp** library is made up of multiple packages: |**Linux/Mac**|[![Build Status](https://travis-ci.org/SixLabors/ImageSharp.svg)](https://travis-ci.org/SixLabors/ImageSharp)|[![Code coverage](https://codecov.io/gh/SixLabors/ImageSharp/branch/master/graph/badge.svg)](https://codecov.io/gh/SixLabors/ImageSharp)| |**Windows** |[![Build Status](https://ci.appveyor.com/api/projects/status/m9pn907xdah3ca39/branch/master?svg=true)](https://ci.appveyor.com/project/six-labors/imagesharp/branch/master)|[![Code coverage](https://codecov.io/gh/SixLabors/ImageSharp/branch/master/graph/badge.svg)](https://codecov.io/gh/SixLabors/ImageSharp)| -### Features +### Questions? -There's plenty there and more coming. Check out the [current features](features.md)! +Do you have questions? We are happy to help! Please [join our gitter channel](https://gitter.im/ImageSharp/General), or ask them on [stackoverflow](https://stackoverflow.com) using the `ImageSharp` tag. ### API -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. +API documentation is available at [https://sixlabors.github.io/docs/](https://sixlabors.github.io/docs/) + +Our API is designed to be simple to consume. 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. On platforms supporting netstandard 1.3+ + ```csharp -// Image.Load(string path) is a shortcut for our default type. Other pixel formats use Image.Load(string path)) +// 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.Mutate(x => x .Resize(image.Width / 2, image.Height / 2) .Grayscale()); - image.Save("bar.jpg"); // automatic encoder selected based on extension. + image.Save("bar.jpg"); // Automatic encoder selected based on extension. } ``` -on netstandard 1.1 - 1.2 +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)) +// 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.Mutate(x => x .Resize(image.Width / 2, image.Height / 2) @@ -81,7 +88,7 @@ using (Image image = Image.Load(stream)) } ``` -Setting individual pixel values can be perfomed as follows: +Setting individual pixel values can be performed as follows: ```csharp // Individual pixels @@ -93,9 +100,7 @@ using (Image image = new Image(400, 400)) `Rgba32` is our default PixelFormat, equivalent to `System.Drawing Color`. For advanced pixel format usage there are multiple [PixelFormat implementations](https://github.com/SixLabors/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. - -**Check out [this blog post](https://sixlabors.com/blog/announcing-imagesharp-beta-1/) or our [Samples Repository](https://github.com/SixLabors/Samples/tree/master/ImageSharp) for more examples!** +**Check out this [blog post](https://sixlabors.com/blog/announcing-imagesharp-beta-1/) or our [Samples Repository](https://github.com/SixLabors/Samples/tree/master/ImageSharp) for more examples!** ### Manual build diff --git a/build/icons/imagesharp-logo-128.png b/build/icons/imagesharp-logo-128.png index f825a4034e..5c2079144f 100644 --- a/build/icons/imagesharp-logo-128.png +++ b/build/icons/imagesharp-logo-128.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e0f7d4c9396d4c7fe8173057c44cc2c0ecc24e52b52ce67c97dd11a7ac6e79ed -size 8113 +oid sha256:148a268c589b628f5d0b5af0e86911a0b393c35b8b25233c71553657c88e0b96 +size 7568 diff --git a/build/icons/imagesharp-logo-256.png b/build/icons/imagesharp-logo-256.png index 3ee8e026f2..e38807ae1e 100644 --- a/build/icons/imagesharp-logo-256.png +++ b/build/icons/imagesharp-logo-256.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7583dab9f399b7b9a7f69fc87086caa439249a705b058d6bfbd88238cfd95d4e -size 16613 +oid sha256:7e4b2ff72aef1979500cd130c28490a00be116bb833bc96ca30c85dc0596099c +size 15413 diff --git a/build/icons/imagesharp-logo-32.png b/build/icons/imagesharp-logo-32.png index fd7cbfa9c3..273b171eb2 100644 --- a/build/icons/imagesharp-logo-32.png +++ b/build/icons/imagesharp-logo-32.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c2b4b7ede0bf2fb4a9d028c9c4e930ab092b8c45689dd288ed1e419b5207048b -size 1904 +oid sha256:021c12313afbdc65f58bfea8c7b436d5c2102513bb63d9e64ee2b61a1344c56a +size 1799 diff --git a/build/icons/imagesharp-logo-512.png b/build/icons/imagesharp-logo-512.png index f1de1fb956..707dc9a35b 100644 --- a/build/icons/imagesharp-logo-512.png +++ b/build/icons/imagesharp-logo-512.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:cd9c567ef861075fcaef709577e87017b5834556df5fc6ff51c4ded8972568a8 -size 35069 +oid sha256:3ae54ae0035df1f8f1459081e2f1d5cceda6f88cca6ec015d8c0209bf0d34edf +size 32534 diff --git a/build/icons/imagesharp-logo-64.png b/build/icons/imagesharp-logo-64.png index e326b9c3a8..17577772eb 100644 --- a/build/icons/imagesharp-logo-64.png +++ b/build/icons/imagesharp-logo-64.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:28a0995e02d0535a13d08997d36cc7b4df95760f9499396b209ad2c7d73ccef6 -size 3962 +oid sha256:92896854265693f28f9a503b9093cb2c9a4a9b329f310732efdd9c6f6c3761bc +size 3736 diff --git a/build/icons/imagesharp-logo-heading.png b/build/icons/imagesharp-logo-heading.png deleted file mode 100644 index 0fe1322052..0000000000 --- a/build/icons/imagesharp-logo-heading.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:9480cb9ac66963e717b7e89666375e8bb23183e456067fd7d445ffb3c182b425 -size 11390 diff --git a/build/icons/imagesharp-logo.png b/build/icons/imagesharp-logo.png index f1de1fb956..707dc9a35b 100644 --- a/build/icons/imagesharp-logo.png +++ b/build/icons/imagesharp-logo.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:cd9c567ef861075fcaef709577e87017b5834556df5fc6ff51c4ded8972568a8 -size 35069 +oid sha256:3ae54ae0035df1f8f1459081e2f1d5cceda6f88cca6ec015d8c0209bf0d34edf +size 32534 diff --git a/build/icons/imagesharp-logo.svg b/build/icons/imagesharp-logo.svg index cd4dfa117d..620287457a 100644 --- a/build/icons/imagesharp-logo.svg +++ b/build/icons/imagesharp-logo.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/features.md b/features.md deleted file mode 100644 index 1e35b88e0d..0000000000 --- a/features.md +++ /dev/null @@ -1,149 +0,0 @@ - -# Features - -### What works so far/ What is planned? - -We've achieved a lot so far and hope to do a lot more in the future. We're always looking for help so please pitch in! - -- **Encoding/decoding of image formats (plugable).** - - [x] Jpeg (Includes Subsampling. Progressive writing required) - - [x] Bmp (Read: 32bit, 24bit, 16 bit. Write: 32bit, 24bit just now) - - [x] Png (Read: Rgb, Rgba, Grayscale, Grayscale + alpha, Palette. Write: Rgb, Rgba, Grayscale, Grayscale + alpha, Palette) Supports interlaced decoding - - [x] Gif (Includes animated) - - [ ] Tiff (Help needed) -- **Metadata** - - [x] EXIF Read/Write (Jpeg just now) - - [ ] ICC (In Progress) -- **Quantizers (IQuantizer with alpha channel support, dithering, and thresholding)** - - [x] Octree - - [x] Xiaolin Wu - - [x] Palette -- **DIthering (Error diffusion and Ordered)** - - [x] Atkinson - - [x] Burks - - [x] FloydSteinburg - - [x] JarvisJudiceNinke - - [x] Sieera2 - - [x] Sierra3 - - [x] SerraLite - - [x] Bayer - - [x] Ordered -- **Basic color structs with implicit operators.** - - [x] Bgra32 - - [x] CIE Lab - - [x] CIE XYZ - - [x] CMYK - - [x] HSV - - [x] HSL - - [x] YCbCr -- **IPackedPixel representations of color models. Compatible with Microsoft XNA Game Studio and MonoGame IPackedVector\.** - - [x] Alpha8 - - [x] Argb32 - - [x] Bgr565 - - [x] Bgra444 - - [x] Bgra565 - - [x] Byte4 - - [x] HalfSingle - - [x] HalfVector2 - - [x] HalfVector4 - - [x] NormalizedByte2 - - [x] NormalizedByte4 - - [x] NormalizedShort2 - - [x] NormalizedShort4 - - [x] Rg32 - - [x] Rgba1010102 - - [x] Rgba32 - 32bit color in RGBA order - Our default pixel format. - - [x] Rgba64 - - [x] RgbaVector - - [x] Short2 - - [x] Short4 -- **Basic shape primitives.** - - [x] Rectangle - - [x] Size - - [x] Point - - [x] Ellipse -- **Resampling algorithms. (Optional gamma correction, resize modes, Performance improvements?)** - - [x] Box - - [x] Bicubic - - [x] Lanczos2 - - [x] Lanczos3 - - [x] Lanczos5 - - [x] Lanczos8 - - [x] MitchelNetravali - - [x] Nearest Neighbour - - [x] Robidoux - - [x] Robidoux Sharp - - [x] Spline - - [x] Triangle - - [x] Welch -- **Padding** - - [x] Pad - - [x] ResizeMode.Pad - - [x] ResizeMode.BoxPad -- **Cropping** - - [x] Rectangular Crop - - [ ] Elliptical Crop - - [x] Entropy Crop - - [x] ResizeMode.Crop -- **Rotation/Skew** - - [x] Flip (90, 270, FlipType etc) - - [x] Rotate by angle and center point (Expandable canvas). - - [x] Skew by x/y angles and center point (Expandable canvas). -- **ColorMatrix operations (Uses Matrix4x4)** - - [x] BlackWhite - - [x] Grayscale BT709 - - [x] Grayscale BT601 - - [x] Hue - - [x] Saturation - - [x] Lomograph - - [x] Polaroid - - [x] Kodachrome - - [x] Sepia - - [x] Achromatomaly - - [x] Achromatopsia - - [x] Deuteranomaly - - [x] Deuteranopia - - [x] Protanomaly - - [x] Protanopia - - [x] Tritanomaly - - [x] Tritanopia -- **Edge Detection** - - [x] Kayyali - - [x] Kirsch - - [x] Laplacian3X3 - - [x] Laplacian5X5 - - [x] LaplacianOfGaussian - - [x] Prewitt - - [x] RobertsCross - - [x] Robinson - - [x] Scharr - - [x] Sobel -- **Blurring/Sharpening** - - [x] Gaussian blur - - [x] Gaussian sharpening - - [x] Box Blur -- **Filters** - - [x] Alpha - - [x] Contrast - - [x] Invert - - [x] BackgroundColor - - [x] Brightness - - [x] Pixelate - - [ ] Mask - - [x] Oil Painting - - [x] Vignette - - [x] Glow - - [x] Threshold -- **Drawing** - - [x] Image brush - - [x] Pattern brush - - [x] Solid brush - - [X] Hatch brush (Partial copy of System.Drawing brushes) - - [x] Pen (Solid, Dash, Custom) - - [x] Line drawing - - [x] Complex Polygons (Fill, draw) - - [x] DrawImage - - [ ] Gradient brush (Need help) -- **DrawingText** - - [ ] DrawString (In-progress. Single variant support just now, no italic,bold) -- Other stuff I haven't thought of. \ No newline at end of file diff --git a/input/about.md b/input/about.md deleted file mode 100644 index 42739928ae..0000000000 --- a/input/about.md +++ /dev/null @@ -1,3 +0,0 @@ -Title: About This Project ---- -This project is awesome! \ No newline at end of file diff --git a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj b/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj index 3e320dccc7..2c4a286d63 100644 --- a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj +++ b/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj @@ -46,7 +46,7 @@ ..\..\ImageSharp.ruleset - SixLabors.ImageSharp.Drawing + SixLabors.ImageSharp true diff --git a/src/ImageSharp.Drawing/Region.cs b/src/ImageSharp.Drawing/Primitives/Region.cs similarity index 95% rename from src/ImageSharp.Drawing/Region.cs rename to src/ImageSharp.Drawing/Primitives/Region.cs index c5e7c1cfd4..c85e373fb3 100644 --- a/src/ImageSharp.Drawing/Region.cs +++ b/src/ImageSharp.Drawing/Primitives/Region.cs @@ -1,10 +1,9 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Drawing +namespace SixLabors.ImageSharp.Primitives { /// /// Represents a region of an image. diff --git a/src/ImageSharp.Drawing/Paths/ShapePath.cs b/src/ImageSharp.Drawing/Primitives/ShapePath.cs similarity index 68% rename from src/ImageSharp.Drawing/Paths/ShapePath.cs rename to src/ImageSharp.Drawing/Primitives/ShapePath.cs index 4c22787195..2a569f0616 100644 --- a/src/ImageSharp.Drawing/Paths/ShapePath.cs +++ b/src/ImageSharp.Drawing/Primitives/ShapePath.cs @@ -1,14 +1,10 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; -using System.Buffers; -using System.Numerics; - -using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.Processing.Drawing.Pens; using SixLabors.Shapes; -namespace SixLabors.ImageSharp.Drawing +namespace SixLabors.ImageSharp.Primitives { /// /// A mapping between a and a region. @@ -20,10 +16,10 @@ namespace SixLabors.ImageSharp.Drawing /// /// The shape. /// The pen to apply to the shape. - // SixLabors.shape willbe moving to a Span/ReadOnlySpan based API shortly use ToArray for now. - public ShapePath(IPath shape, Pens.IPen pen) + // TODO: SixLabors.shape will be moving to a Span/ReadOnlySpan based API shortly use ToArray for now. + public ShapePath(IPath shape, IPen pen) : base(shape.GenerateOutline(pen.StrokeWidth, pen.StrokePattern.ToArray())) { } } -} +} \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Paths/ShapeRegion.cs b/src/ImageSharp.Drawing/Primitives/ShapeRegion.cs similarity index 91% rename from src/ImageSharp.Drawing/Paths/ShapeRegion.cs rename to src/ImageSharp.Drawing/Primitives/ShapeRegion.cs index cc27f7fbb8..cfd1945d08 100644 --- a/src/ImageSharp.Drawing/Paths/ShapeRegion.cs +++ b/src/ImageSharp.Drawing/Primitives/ShapeRegion.cs @@ -2,13 +2,10 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Buffers; -using System.Numerics; -using SixLabors.ImageSharp.Memory; using SixLabors.Primitives; using SixLabors.Shapes; -namespace SixLabors.ImageSharp.Drawing +namespace SixLabors.ImageSharp.Primitives { /// /// A mapping between a and a region. @@ -48,7 +45,7 @@ namespace SixLabors.ImageSharp.Drawing var end = new PointF(this.Bounds.Right + 1, y); // TODO: This is a temporary workaround because of the lack of Span API-s on IPath. We should use MemoryManager.Allocate() here! - PointF[] innerBuffer = new PointF[buffer.Length]; + var innerBuffer = new PointF[buffer.Length]; int count = this.Shape.FindIntersections(start, end, innerBuffer, 0); for (int i = 0; i < count; i++) diff --git a/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/BrushApplicator.cs similarity index 92% rename from src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs rename to src/ImageSharp.Drawing/Processing/Drawing/Brushes/BrushApplicator.cs index d8ea435586..f665e8408c 100644 --- a/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/BrushApplicator.cs @@ -6,7 +6,7 @@ using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Drawing.Brushes.Processors +namespace SixLabors.ImageSharp.Processing.Drawing.Brushes { /// /// primitive that converts a point in to a color for discovering the fill color based on an implementation @@ -31,12 +31,12 @@ namespace SixLabors.ImageSharp.Drawing.Brushes.Processors } /// - /// Gets the blendder + /// Gets the blender /// internal PixelBlender Blender { get; } /// - /// Gets the destinaion + /// Gets the destination /// protected ImageFrame Target { get; } @@ -48,8 +48,8 @@ namespace SixLabors.ImageSharp.Drawing.Brushes.Processors /// /// Gets the color for a single pixel. /// - /// The x cordinate. - /// The y cordinate. + /// The x coordinate. + /// The y coordinate. /// The a that should be applied to the pixel. internal abstract TPixel this[int x, int y] { get; } @@ -57,7 +57,7 @@ namespace SixLabors.ImageSharp.Drawing.Brushes.Processors public abstract void Dispose(); /// - /// Applies the opactiy weighting for each pixel in a scanline to the target based on the pattern contained in the brush. + /// Applies the opacity weighting for each pixel in a scanline to the target based on the pattern contained in the brush. /// /// The a collection of opacity values between 0 and 1 to be merged with the brushed color value before being applied to the target. /// The x position in the target pixel space that the start of the scanline data corresponds to. diff --git a/src/ImageSharp.Drawing/Brushes/Brushes.cs b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/Brushes.cs similarity index 99% rename from src/ImageSharp.Drawing/Brushes/Brushes.cs rename to src/ImageSharp.Drawing/Processing/Drawing/Brushes/Brushes.cs index 47e207e8c4..141ca403b3 100644 --- a/src/ImageSharp.Drawing/Brushes/Brushes.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/Brushes.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Drawing.Brushes +namespace SixLabors.ImageSharp.Processing.Drawing.Brushes { /// /// A collection of methods for creating generic brushes. diff --git a/src/ImageSharp.Drawing/Brushes/IBrush.cs b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/IBrush.cs similarity index 90% rename from src/ImageSharp.Drawing/Brushes/IBrush.cs rename to src/ImageSharp.Drawing/Processing/Drawing/Brushes/IBrush.cs index bb907281b0..93ecb7788c 100644 --- a/src/ImageSharp.Drawing/Brushes/IBrush.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/IBrush.cs @@ -1,12 +1,10 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Drawing.Brushes.Processors; -using SixLabors.ImageSharp.Drawing.Processors; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Drawing.Brushes +namespace SixLabors.ImageSharp.Processing.Drawing.Brushes { /// /// Brush represents a logical configuration of a brush which can be used to source pixel colors diff --git a/src/ImageSharp.Drawing/Brushes/ImageBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/ImageBrush{TPixel}.cs similarity index 95% rename from src/ImageSharp.Drawing/Brushes/ImageBrush{TPixel}.cs rename to src/ImageSharp.Drawing/Processing/Drawing/Brushes/ImageBrush{TPixel}.cs index 320c94c96b..c2e3a16eff 100644 --- a/src/ImageSharp.Drawing/Brushes/ImageBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/ImageBrush{TPixel}.cs @@ -3,13 +3,11 @@ using System; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Drawing.Brushes.Processors; -using SixLabors.ImageSharp.Drawing.Processors; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Drawing.Brushes +namespace SixLabors.ImageSharp.Processing.Drawing.Brushes { /// /// Provides an implementation of an image brush for painting images within areas. @@ -43,9 +41,7 @@ namespace SixLabors.ImageSharp.Drawing.Brushes /// public BrushApplicator CreateApplicator(ImageFrame source, RectangleF region, GraphicsOptions options) - { - return new ImageBrushApplicator(source, this.image, region, options); - } + => new ImageBrushApplicator(source, this.image, region, options); /// /// The image brush applicator. diff --git a/src/ImageSharp.Drawing/Brushes/PatternBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/PatternBrush{TPixel}.cs similarity index 86% rename from src/ImageSharp.Drawing/Brushes/PatternBrush{TPixel}.cs rename to src/ImageSharp.Drawing/Processing/Drawing/Brushes/PatternBrush{TPixel}.cs index cc22b26391..765f2a1326 100644 --- a/src/ImageSharp.Drawing/Brushes/PatternBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/PatternBrush{TPixel}.cs @@ -4,13 +4,12 @@ using System; using System.Numerics; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Drawing.Brushes.Processors; -using SixLabors.ImageSharp.Drawing.Processors; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Primitives; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Drawing.Brushes +namespace SixLabors.ImageSharp.Processing.Drawing.Brushes { /// /// Provides an implementation of a pattern brush for painting patterns. @@ -40,8 +39,8 @@ namespace SixLabors.ImageSharp.Drawing.Brushes /// /// The pattern. /// - private readonly Fast2DArray pattern; - private readonly Fast2DArray patternVector; + private readonly DenseMatrix pattern; + private readonly DenseMatrix patternVector; /// /// Initializes a new instance of the class. @@ -50,7 +49,7 @@ namespace SixLabors.ImageSharp.Drawing.Brushes /// Color of the back. /// The pattern. public PatternBrush(TPixel foreColor, TPixel backColor, bool[,] pattern) - : this(foreColor, backColor, new Fast2DArray(pattern)) + : this(foreColor, backColor, new DenseMatrix(pattern)) { } @@ -60,12 +59,12 @@ namespace SixLabors.ImageSharp.Drawing.Brushes /// Color of the fore. /// Color of the back. /// The pattern. - internal PatternBrush(TPixel foreColor, TPixel backColor, Fast2DArray pattern) + internal PatternBrush(TPixel foreColor, TPixel backColor, DenseMatrix pattern) { var foreColorVector = foreColor.ToVector4(); var backColorVector = backColor.ToVector4(); - this.pattern = new Fast2DArray(pattern.Width, pattern.Height); - this.patternVector = new Fast2DArray(pattern.Width, pattern.Height); + this.pattern = new DenseMatrix(pattern.Columns, pattern.Rows); + this.patternVector = new DenseMatrix(pattern.Columns, pattern.Rows); for (int i = 0; i < pattern.Data.Length; i++) { if (pattern.Data[i]) @@ -105,8 +104,8 @@ namespace SixLabors.ImageSharp.Drawing.Brushes /// /// The pattern. /// - private readonly Fast2DArray pattern; - private readonly Fast2DArray patternVector; + private readonly DenseMatrix pattern; + private readonly DenseMatrix patternVector; /// /// Initializes a new instance of the class. @@ -115,7 +114,7 @@ namespace SixLabors.ImageSharp.Drawing.Brushes /// The pattern. /// The patternVector. /// The options - public PatternBrushApplicator(ImageFrame source, Fast2DArray pattern, Fast2DArray patternVector, GraphicsOptions options) + public PatternBrushApplicator(ImageFrame source, DenseMatrix pattern, DenseMatrix patternVector, GraphicsOptions options) : base(source, options) { this.pattern = pattern; @@ -134,8 +133,8 @@ namespace SixLabors.ImageSharp.Drawing.Brushes { get { - x = x % this.pattern.Width; - y = y % this.pattern.Height; + x = x % this.pattern.Columns; + y = y % this.pattern.Rows; // 2d array index at row/column return this.pattern[y, x]; @@ -151,7 +150,7 @@ namespace SixLabors.ImageSharp.Drawing.Brushes /// internal override void Apply(Span scanline, int x, int y) { - int patternY = y % this.pattern.Height; + int patternY = y % this.pattern.Rows; MemoryManager memoryManager = this.Target.MemoryManager; using (IBuffer amountBuffer = memoryManager.Allocate(scanline.Length)) @@ -164,7 +163,7 @@ namespace SixLabors.ImageSharp.Drawing.Brushes { amountSpan[i] = (scanline[i] * this.Options.BlendPercentage).Clamp(0, 1); - int patternX = (x + i) % this.pattern.Width; + int patternX = (x + i) % this.pattern.Columns; overlaySpan[i] = this.pattern[patternY, patternX]; } diff --git a/src/ImageSharp.Drawing/Brushes/RecolorBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/RecolorBrush{TPixel}.cs similarity index 88% rename from src/ImageSharp.Drawing/Brushes/RecolorBrush{TPixel}.cs rename to src/ImageSharp.Drawing/Processing/Drawing/Brushes/RecolorBrush{TPixel}.cs index 39afd965c8..324c54e186 100644 --- a/src/ImageSharp.Drawing/Brushes/RecolorBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/RecolorBrush{TPixel}.cs @@ -4,13 +4,11 @@ using System; using System.Numerics; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Drawing.Brushes.Processors; -using SixLabors.ImageSharp.Drawing.Processors; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Drawing.Brushes +namespace SixLabors.ImageSharp.Processing.Drawing.Brushes { /// /// Provides an implementation of a brush that can recolor an image @@ -23,21 +21,18 @@ namespace SixLabors.ImageSharp.Drawing.Brushes /// Initializes a new instance of the class. /// /// Color of the source. - /// Color of the target. + /// Color of the target. /// The threshold as a value between 0 and 1. - public RecolorBrush(TPixel sourceColor, TPixel targeTPixel, float threshold) + public RecolorBrush(TPixel sourceColor, TPixel targetColor, float threshold) { this.SourceColor = sourceColor; this.Threshold = threshold; - this.TargeTPixel = targeTPixel; + this.TargetColor = targetColor; } /// /// Gets the threshold. /// - /// - /// The threshold. - /// public float Threshold { get; } /// @@ -51,15 +46,12 @@ namespace SixLabors.ImageSharp.Drawing.Brushes /// /// Gets the target color. /// - /// - /// The color of the target. - /// - public TPixel TargeTPixel { get; } + public TPixel TargetColor { get; } /// public BrushApplicator CreateApplicator(ImageFrame source, RectangleF region, GraphicsOptions options) { - return new RecolorBrushApplicator(source, this.SourceColor, this.TargeTPixel, this.Threshold, options); + return new RecolorBrushApplicator(source, this.SourceColor, this.TargetColor, this.Threshold, options); } /// @@ -99,7 +91,7 @@ namespace SixLabors.ImageSharp.Drawing.Brushes this.targetColor = targetColor.ToVector4(); this.targetColorPixel = targetColor; - // Lets hack a min max extreams for a color space by letting the IPackedPixel clamp our values to something in the correct spaces :) + // Lets hack a min max extremes for a color space by letting the IPackedPixel clamp our values to something in the correct spaces :) var maxColor = default(TPixel); maxColor.PackFromVector4(new Vector4(float.MaxValue)); var minColor = default(TPixel); @@ -158,8 +150,8 @@ namespace SixLabors.ImageSharp.Drawing.Brushes int offsetX = x + i; - // no doubt this one can be optermised further but I can't imagine its - // actually being used and can probably be removed/interalised for now + // No doubt this one can be optimized further but I can't imagine its + // actually being used and can probably be removed/internalized for now overlaySpan[i] = this[offsetX, y]; } diff --git a/src/ImageSharp.Drawing/Brushes/SolidBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/SolidBrush{TPixel}.cs similarity index 95% rename from src/ImageSharp.Drawing/Brushes/SolidBrush{TPixel}.cs rename to src/ImageSharp.Drawing/Processing/Drawing/Brushes/SolidBrush{TPixel}.cs index 9630c707ef..826f5f60a7 100644 --- a/src/ImageSharp.Drawing/Brushes/SolidBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/SolidBrush{TPixel}.cs @@ -2,15 +2,12 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Numerics; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Drawing.Brushes.Processors; -using SixLabors.ImageSharp.Drawing.Processors; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Drawing.Brushes +namespace SixLabors.ImageSharp.Processing.Drawing.Brushes { /// /// Provides an implementation of a solid brush for painting solid color areas. diff --git a/src/ImageSharp.Drawing/Paths/DrawBeziers.cs b/src/ImageSharp.Drawing/Processing/Drawing/DrawBezierExtensions.cs similarity index 70% rename from src/ImageSharp.Drawing/Paths/DrawBeziers.cs rename to src/ImageSharp.Drawing/Processing/Drawing/DrawBezierExtensions.cs index de4fdd003b..8f075d5c2c 100644 --- a/src/ImageSharp.Drawing/Paths/DrawBeziers.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/DrawBezierExtensions.cs @@ -1,23 +1,21 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System.Numerics; -using SixLabors.ImageSharp.Drawing; -using SixLabors.ImageSharp.Drawing.Brushes; -using SixLabors.ImageSharp.Drawing.Pens; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Drawing.Brushes; +using SixLabors.ImageSharp.Processing.Drawing.Pens; using SixLabors.Primitives; using SixLabors.Shapes; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Drawing { /// - /// Extension methods for the type. + /// Adds extensions that allow the drawing of Bezier paths to the type. /// - public static partial class ImageExtensions + public static class DrawBezierExtensions { /// - /// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush + /// Draws the provided points as an open Bezier path at the provided thickness with the supplied brush /// /// The type of the color. /// The image this method extends. @@ -27,13 +25,11 @@ namespace SixLabors.ImageSharp /// The options. /// The . public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) - where TPixel : struct, IPixel - { - return source.Draw(new Pen(brush, thickness), new Path(new CubicBezierLineSegment(points)), options); - } + where TPixel : struct, IPixel + => source.Draw(new Pen(brush, thickness), new Path(new CubicBezierLineSegment(points)), options); /// - /// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush + /// Draws the provided points as an open Bezier path at the provided thickness with the supplied brush /// /// The type of the color. /// The image this method extends. @@ -42,13 +38,11 @@ namespace SixLabors.ImageSharp /// The points. /// The . public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, IBrush brush, float thickness, PointF[] points) - where TPixel : struct, IPixel - { - return source.Draw(new Pen(brush, thickness), new Path(new CubicBezierLineSegment(points))); - } + where TPixel : struct, IPixel + => source.Draw(new Pen(brush, thickness), new Path(new CubicBezierLineSegment(points))); /// - /// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush + /// Draws the provided points as an open Bezier path at the provided thickness with the supplied brush /// /// The type of the color. /// The image this method extends. @@ -57,13 +51,11 @@ namespace SixLabors.ImageSharp /// The points. /// The . public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, TPixel color, float thickness, PointF[] points) - where TPixel : struct, IPixel - { - return source.DrawBeziers(new SolidBrush(color), thickness, points); - } + where TPixel : struct, IPixel + => source.DrawBeziers(new SolidBrush(color), thickness, points); /// - /// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush + /// Draws the provided points as an open Bezier path at the provided thickness with the supplied brush /// /// The type of the color. /// The image this method extends. @@ -73,13 +65,11 @@ namespace SixLabors.ImageSharp /// The options. /// The . public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) - where TPixel : struct, IPixel - { - return source.DrawBeziers(new SolidBrush(color), thickness, points, options); - } + where TPixel : struct, IPixel + => source.DrawBeziers(new SolidBrush(color), thickness, points, options); /// - /// Draws the provided Points as an open Bezier path with the supplied pen + /// Draws the provided points as an open Bezier path with the supplied pen /// /// The type of the color. /// The image this method extends. @@ -88,13 +78,11 @@ namespace SixLabors.ImageSharp /// The options. /// The . public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, IPen pen, PointF[] points, GraphicsOptions options) - where TPixel : struct, IPixel - { - return source.Draw(pen, new Path(new CubicBezierLineSegment(points)), options); - } + where TPixel : struct, IPixel + => source.Draw(pen, new Path(new CubicBezierLineSegment(points)), options); /// - /// Draws the provided Points as an open Bezier path with the supplied pen + /// Draws the provided points as an open Bezier path with the supplied pen /// /// The type of the color. /// The image this method extends. @@ -102,9 +90,7 @@ namespace SixLabors.ImageSharp /// The points. /// The . public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, IPen pen, PointF[] points) - where TPixel : struct, IPixel - { - return source.Draw(pen, new Path(new CubicBezierLineSegment(points))); - } + where TPixel : struct, IPixel + => source.Draw(pen, new Path(new CubicBezierLineSegment(points))); } } diff --git a/src/ImageSharp.Drawing/DrawImage.cs b/src/ImageSharp.Drawing/Processing/Drawing/DrawImageExtensions.cs similarity index 79% rename from src/ImageSharp.Drawing/DrawImage.cs rename to src/ImageSharp.Drawing/Processing/Drawing/DrawImageExtensions.cs index f1db72db60..6187682067 100644 --- a/src/ImageSharp.Drawing/DrawImage.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/DrawImageExtensions.cs @@ -1,33 +1,17 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Drawing.Processors; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Drawing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Drawing { /// - /// Extension methods for the type. + /// Adds extensions that allow the drawing of images to the type. /// - public static partial class ImageExtensions + public static class DrawImageExtensions { - /// - /// Draws the given image together with the current one by blending their pixels. - /// - /// The image this method extends. - /// The image to blend with the currently processing image. - /// The pixel format. - /// The location to draw the blended image. - /// The options. - /// The . - public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, Point location, GraphicsOptions options) - where TPixel : struct, IPixel - { - source.ApplyProcessor(new DrawImageProcessor(image, location, options)); - return source; - } - /// /// Draws the given image together with the current one by blending their pixels. /// @@ -38,11 +22,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Blend(this IImageProcessingContext source, Image image, float opacity) where TPixel : struct, IPixel - { - GraphicsOptions options = GraphicsOptions.Default; - options.BlendPercentage = opacity; - return DrawImage(source, image, Point.Empty, options); - } + => source.ApplyProcessor(new DrawImageProcessor(image, opacity)); /// /// Draws the given image together with the current one by blending their pixels. @@ -55,12 +35,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Blend(this IImageProcessingContext source, Image image, PixelBlenderMode blender, float opacity) where TPixel : struct, IPixel - { - GraphicsOptions options = GraphicsOptions.Default; - options.BlendPercentage = opacity; - options.BlenderMode = blender; - return DrawImage(source, image, Point.Empty, options); - } + => source.ApplyProcessor(new DrawImageProcessor(image, opacity, blender)); /// /// Draws the given image together with the current one by blending their pixels. @@ -73,7 +48,7 @@ namespace SixLabors.ImageSharp public static IImageProcessingContext Blend(this IImageProcessingContext source, Image image, GraphicsOptions options) where TPixel : struct, IPixel { - return DrawImage(source, image, Point.Empty, options); + return source.ApplyProcessor(new DrawImageProcessor(image, options)); } /// @@ -87,11 +62,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, float opacity, Point location) where TPixel : struct, IPixel - { - GraphicsOptions options = GraphicsOptions.Default; - options.BlendPercentage = opacity; - return source.DrawImage(image, location, options); - } + => source.ApplyProcessor(new DrawImageProcessor(image, location, opacity)); /// /// Draws the given image together with the current one by blending their pixels. @@ -105,11 +76,19 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, PixelBlenderMode blender, float opacity, Point location) where TPixel : struct, IPixel - { - GraphicsOptions options = GraphicsOptions.Default; - options.BlenderMode = blender; - options.BlendPercentage = opacity; - return source.DrawImage(image, location, options); - } + => source.ApplyProcessor(new DrawImageProcessor(image, location, opacity, blender)); + + /// + /// Draws the given image together with the current one by blending their pixels. + /// + /// The image this method extends. + /// The image to blend with the currently processing image. + /// The pixel format. + /// The location to draw the blended image. + /// The options containing the blend mode and opacity. + /// The . + public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, Point location, GraphicsOptions options) + where TPixel : struct, IPixel + => source.ApplyProcessor(new DrawImageProcessor(image, location, options)); } } \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Paths/DrawLines.cs b/src/ImageSharp.Drawing/Processing/Drawing/DrawLineExtensions.cs similarity index 77% rename from src/ImageSharp.Drawing/Paths/DrawLines.cs rename to src/ImageSharp.Drawing/Processing/Drawing/DrawLineExtensions.cs index e5d9a1b3b4..9d2ea0c1d8 100644 --- a/src/ImageSharp.Drawing/Paths/DrawLines.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/DrawLineExtensions.cs @@ -1,20 +1,18 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System.Numerics; -using SixLabors.ImageSharp.Drawing; -using SixLabors.ImageSharp.Drawing.Brushes; -using SixLabors.ImageSharp.Drawing.Pens; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Drawing.Brushes; +using SixLabors.ImageSharp.Processing.Drawing.Pens; using SixLabors.Primitives; using SixLabors.Shapes; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Drawing { /// - /// Extension methods for the type. + /// Adds extensions that allow the drawing of lines to the type. /// - public static partial class ImageExtensions + public static class DrawLineExtensions { /// /// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush @@ -27,10 +25,8 @@ namespace SixLabors.ImageSharp /// The options. /// The . public static IImageProcessingContext DrawLines(this IImageProcessingContext source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) - where TPixel : struct, IPixel - { - return source.Draw(new Pen(brush, thickness), new Path(new LinearLineSegment(points)), options); - } + where TPixel : struct, IPixel + => source.Draw(new Pen(brush, thickness), new Path(new LinearLineSegment(points)), options); /// /// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush @@ -42,10 +38,8 @@ namespace SixLabors.ImageSharp /// The points. /// The . public static IImageProcessingContext DrawLines(this IImageProcessingContext source, IBrush brush, float thickness, PointF[] points) - where TPixel : struct, IPixel - { - return source.Draw(new Pen(brush, thickness), new Path(new LinearLineSegment(points))); - } + where TPixel : struct, IPixel + => source.Draw(new Pen(brush, thickness), new Path(new LinearLineSegment(points))); /// /// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush @@ -57,10 +51,8 @@ namespace SixLabors.ImageSharp /// The points. /// The . public static IImageProcessingContext DrawLines(this IImageProcessingContext source, TPixel color, float thickness, PointF[] points) - where TPixel : struct, IPixel - { - return source.DrawLines(new SolidBrush(color), thickness, points); - } + where TPixel : struct, IPixel + => source.DrawLines(new SolidBrush(color), thickness, points); /// /// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush @@ -73,10 +65,8 @@ namespace SixLabors.ImageSharp /// The options. /// The .> public static IImageProcessingContext DrawLines(this IImageProcessingContext source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) - where TPixel : struct, IPixel - { - return source.DrawLines(new SolidBrush(color), thickness, points, options); - } + where TPixel : struct, IPixel + => source.DrawLines(new SolidBrush(color), thickness, points, options); /// /// Draws the provided Points as an open Linear path with the supplied pen @@ -88,10 +78,8 @@ namespace SixLabors.ImageSharp /// The options. /// The . public static IImageProcessingContext DrawLines(this IImageProcessingContext source, IPen pen, PointF[] points, GraphicsOptions options) - where TPixel : struct, IPixel - { - return source.Draw(pen, new Path(new LinearLineSegment(points)), options); - } + where TPixel : struct, IPixel + => source.Draw(pen, new Path(new LinearLineSegment(points)), options); /// /// Draws the provided Points as an open Linear path with the supplied pen @@ -102,9 +90,7 @@ namespace SixLabors.ImageSharp /// The points. /// The . public static IImageProcessingContext DrawLines(this IImageProcessingContext source, IPen pen, PointF[] points) - where TPixel : struct, IPixel - { - return source.Draw(pen, new Path(new LinearLineSegment(points))); - } + where TPixel : struct, IPixel + => source.Draw(pen, new Path(new LinearLineSegment(points))); } } diff --git a/src/ImageSharp.Drawing/Paths/DrawPathCollection.cs b/src/ImageSharp.Drawing/Processing/Drawing/DrawPathCollectionExtensions.cs similarity index 81% rename from src/ImageSharp.Drawing/Paths/DrawPathCollection.cs rename to src/ImageSharp.Drawing/Processing/Drawing/DrawPathCollectionExtensions.cs index a126663b05..d148638ae1 100644 --- a/src/ImageSharp.Drawing/Paths/DrawPathCollection.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/DrawPathCollectionExtensions.cs @@ -1,18 +1,17 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Drawing; -using SixLabors.ImageSharp.Drawing.Brushes; -using SixLabors.ImageSharp.Drawing.Pens; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Drawing.Brushes; +using SixLabors.ImageSharp.Processing.Drawing.Pens; using SixLabors.Shapes; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Drawing { /// - /// Extension methods for the type. + /// Adds extensions that allow the drawing of collections of polygon outlines to the type. /// - public static partial class ImageExtensions + public static class DrawPathCollectionExtensions { /// /// Draws the outline of the polygon with the provided pen. @@ -43,10 +42,8 @@ namespace SixLabors.ImageSharp /// The paths. /// The . public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, IPathCollection paths) - where TPixel : struct, IPixel - { - return source.Draw(pen, paths, GraphicsOptions.Default); - } + where TPixel : struct, IPixel + => source.Draw(pen, paths, GraphicsOptions.Default); /// /// Draws the outline of the polygon with the provided brush at the provided thickness. @@ -59,10 +56,8 @@ namespace SixLabors.ImageSharp /// The options. /// The . public static IImageProcessingContext Draw(this IImageProcessingContext source, IBrush brush, float thickness, IPathCollection paths, GraphicsOptions options) - where TPixel : struct, IPixel - { - return source.Draw(new Pen(brush, thickness), paths, options); - } + where TPixel : struct, IPixel + => source.Draw(new Pen(brush, thickness), paths, options); /// /// Draws the outline of the polygon with the provided brush at the provided thickness. @@ -74,10 +69,8 @@ namespace SixLabors.ImageSharp /// The paths. /// The . public static IImageProcessingContext Draw(this IImageProcessingContext source, IBrush brush, float thickness, IPathCollection paths) - where TPixel : struct, IPixel - { - return source.Draw(new Pen(brush, thickness), paths); - } + where TPixel : struct, IPixel + => source.Draw(new Pen(brush, thickness), paths); /// /// Draws the outline of the polygon with the provided brush at the provided thickness. @@ -90,10 +83,8 @@ namespace SixLabors.ImageSharp /// The options. /// The . public static IImageProcessingContext Draw(this IImageProcessingContext source, TPixel color, float thickness, IPathCollection paths, GraphicsOptions options) - where TPixel : struct, IPixel - { - return source.Draw(new SolidBrush(color), thickness, paths, options); - } + where TPixel : struct, IPixel + => source.Draw(new SolidBrush(color), thickness, paths, options); /// /// Draws the outline of the polygon with the provided brush at the provided thickness. @@ -105,9 +96,7 @@ namespace SixLabors.ImageSharp /// The paths. /// The . public static IImageProcessingContext Draw(this IImageProcessingContext source, TPixel color, float thickness, IPathCollection paths) - where TPixel : struct, IPixel - { - return source.Draw(new SolidBrush(color), thickness, paths); - } + where TPixel : struct, IPixel + => source.Draw(new SolidBrush(color), thickness, paths); } -} +} \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Paths/DrawPath.cs b/src/ImageSharp.Drawing/Processing/Drawing/DrawPathExtensions.cs similarity index 78% rename from src/ImageSharp.Drawing/Paths/DrawPath.cs rename to src/ImageSharp.Drawing/Processing/Drawing/DrawPathExtensions.cs index b6c821a60b..a795ee295b 100644 --- a/src/ImageSharp.Drawing/Paths/DrawPath.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/DrawPathExtensions.cs @@ -1,18 +1,18 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Drawing; -using SixLabors.ImageSharp.Drawing.Brushes; -using SixLabors.ImageSharp.Drawing.Pens; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Primitives; +using SixLabors.ImageSharp.Processing.Drawing.Brushes; +using SixLabors.ImageSharp.Processing.Drawing.Pens; using SixLabors.Shapes; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Drawing { /// - /// Extension methods for the type. + /// Adds extensions that allow the drawing of polygon outlines to the type. /// - public static partial class ImageExtensions + public static class DrawPathExtensions { /// /// Draws the outline of the polygon with the provided pen. @@ -24,10 +24,8 @@ namespace SixLabors.ImageSharp /// The options. /// The . public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, IPath path, GraphicsOptions options) - where TPixel : struct, IPixel - { - return source.Fill(pen.StrokeFill, new ShapePath(path, pen), options); - } + where TPixel : struct, IPixel + => source.Fill(pen.StrokeFill, new ShapePath(path, pen), options); /// /// Draws the outline of the polygon with the provided pen. @@ -38,10 +36,8 @@ namespace SixLabors.ImageSharp /// The path. /// The . public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, IPath path) - where TPixel : struct, IPixel - { - return source.Draw(pen, path, GraphicsOptions.Default); - } + where TPixel : struct, IPixel + => source.Draw(pen, path, GraphicsOptions.Default); /// /// Draws the outline of the polygon with the provided brush at the provided thickness. @@ -54,10 +50,8 @@ namespace SixLabors.ImageSharp /// The options. /// The . public static IImageProcessingContext Draw(this IImageProcessingContext source, IBrush brush, float thickness, IPath path, GraphicsOptions options) - where TPixel : struct, IPixel - { - return source.Draw(new Pen(brush, thickness), path, options); - } + where TPixel : struct, IPixel + => source.Draw(new Pen(brush, thickness), path, options); /// /// Draws the outline of the polygon with the provided brush at the provided thickness. @@ -69,10 +63,8 @@ namespace SixLabors.ImageSharp /// The path. /// The . public static IImageProcessingContext Draw(this IImageProcessingContext source, IBrush brush, float thickness, IPath path) - where TPixel : struct, IPixel - { - return source.Draw(new Pen(brush, thickness), path); - } + where TPixel : struct, IPixel + => source.Draw(new Pen(brush, thickness), path); /// /// Draws the outline of the polygon with the provided brush at the provided thickness. @@ -85,10 +77,8 @@ namespace SixLabors.ImageSharp /// The options. /// The . public static IImageProcessingContext Draw(this IImageProcessingContext source, TPixel color, float thickness, IPath path, GraphicsOptions options) - where TPixel : struct, IPixel - { - return source.Draw(new SolidBrush(color), thickness, path, options); - } + where TPixel : struct, IPixel + => source.Draw(new SolidBrush(color), thickness, path, options); /// /// Draws the outline of the polygon with the provided brush at the provided thickness. @@ -100,9 +90,7 @@ namespace SixLabors.ImageSharp /// The path. /// The . public static IImageProcessingContext Draw(this IImageProcessingContext source, TPixel color, float thickness, IPath path) - where TPixel : struct, IPixel - { - return source.Draw(new SolidBrush(color), thickness, path); - } + where TPixel : struct, IPixel + => source.Draw(new SolidBrush(color), thickness, path); } } diff --git a/src/ImageSharp.Drawing/Paths/DrawPolygon.cs b/src/ImageSharp.Drawing/Processing/Drawing/DrawPolygonExtensions.cs similarity index 77% rename from src/ImageSharp.Drawing/Paths/DrawPolygon.cs rename to src/ImageSharp.Drawing/Processing/Drawing/DrawPolygonExtensions.cs index 771ea9e616..833b616f89 100644 --- a/src/ImageSharp.Drawing/Paths/DrawPolygon.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/DrawPolygonExtensions.cs @@ -1,20 +1,18 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System.Numerics; -using SixLabors.ImageSharp.Drawing; -using SixLabors.ImageSharp.Drawing.Brushes; -using SixLabors.ImageSharp.Drawing.Pens; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Drawing.Brushes; +using SixLabors.ImageSharp.Processing.Drawing.Pens; using SixLabors.Primitives; using SixLabors.Shapes; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Drawing { /// - /// Extension methods for the type. + /// Adds extensions that allow the drawing of closed linear polygons to the type. /// - public static partial class ImageExtensions + public static class DrawPolygonExtensions { /// /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness. @@ -27,10 +25,8 @@ namespace SixLabors.ImageSharp /// The options. /// The . public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) - where TPixel : struct, IPixel - { - return source.Draw(new Pen(brush, thickness), new Polygon(new LinearLineSegment(points)), options); - } + where TPixel : struct, IPixel + => source.Draw(new Pen(brush, thickness), new Polygon(new LinearLineSegment(points)), options); /// /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness. @@ -42,10 +38,8 @@ namespace SixLabors.ImageSharp /// The points. /// The . public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, IBrush brush, float thickness, PointF[] points) - where TPixel : struct, IPixel - { - return source.Draw(new Pen(brush, thickness), new Polygon(new LinearLineSegment(points))); - } + where TPixel : struct, IPixel + => source.Draw(new Pen(brush, thickness), new Polygon(new LinearLineSegment(points))); /// /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness. @@ -57,10 +51,8 @@ namespace SixLabors.ImageSharp /// The points. /// The . public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, TPixel color, float thickness, PointF[] points) - where TPixel : struct, IPixel - { - return source.DrawPolygon(new SolidBrush(color), thickness, points); - } + where TPixel : struct, IPixel + => source.DrawPolygon(new SolidBrush(color), thickness, points); /// /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness. @@ -73,10 +65,8 @@ namespace SixLabors.ImageSharp /// The options. /// The . public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) - where TPixel : struct, IPixel - { - return source.DrawPolygon(new SolidBrush(color), thickness, points, options); - } + where TPixel : struct, IPixel + => source.DrawPolygon(new SolidBrush(color), thickness, points, options); /// /// Draws the provided Points as a closed Linear Polygon with the provided Pen. @@ -87,10 +77,8 @@ namespace SixLabors.ImageSharp /// The points. /// The . public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, IPen pen, PointF[] points) - where TPixel : struct, IPixel - { - return source.Draw(pen, new Polygon(new LinearLineSegment(points)), GraphicsOptions.Default); - } + where TPixel : struct, IPixel + => source.Draw(pen, new Polygon(new LinearLineSegment(points)), GraphicsOptions.Default); /// /// Draws the provided Points as a closed Linear Polygon with the provided Pen. @@ -102,9 +90,7 @@ namespace SixLabors.ImageSharp /// The options. /// The . public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, IPen pen, PointF[] points, GraphicsOptions options) - where TPixel : struct, IPixel - { - return source.Draw(pen, new Polygon(new LinearLineSegment(points)), options); - } + where TPixel : struct, IPixel + => source.Draw(pen, new Polygon(new LinearLineSegment(points)), options); } -} +} \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Paths/DrawRectangle.cs b/src/ImageSharp.Drawing/Processing/Drawing/DrawRectangleExtensions.cs similarity index 68% rename from src/ImageSharp.Drawing/Paths/DrawRectangle.cs rename to src/ImageSharp.Drawing/Processing/Drawing/DrawRectangleExtensions.cs index 6b98d1f8e9..3d6702be97 100644 --- a/src/ImageSharp.Drawing/Paths/DrawRectangle.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/DrawRectangleExtensions.cs @@ -1,21 +1,21 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Drawing; -using SixLabors.ImageSharp.Drawing.Brushes; -using SixLabors.ImageSharp.Drawing.Pens; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Drawing.Brushes; +using SixLabors.ImageSharp.Processing.Drawing.Pens; using SixLabors.Primitives; +using SixLabors.Shapes; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Drawing { /// - /// Extension methods for the type. + /// Adds extensions that allow the drawing of rectangles to the type. /// - public static partial class ImageExtensions + public static class DrawRectangleExtensions { /// - /// Draws the outline of the polygon with the provided pen. + /// Draws the outline of the rectangle with the provided pen. /// /// The type of the color. /// The image this method extends. @@ -24,13 +24,11 @@ namespace SixLabors.ImageSharp /// The options. /// The . public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, RectangleF shape, GraphicsOptions options) - where TPixel : struct, IPixel - { - return source.Draw(pen, new SixLabors.Shapes.RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height), options); - } + where TPixel : struct, IPixel + => source.Draw(pen, new RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height), options); /// - /// Draws the outline of the polygon with the provided pen. + /// Draws the outline of the rectangle with the provided pen. /// /// The type of the color. /// The image this method extends. @@ -38,13 +36,11 @@ namespace SixLabors.ImageSharp /// The shape. /// The . public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, RectangleF shape) - where TPixel : struct, IPixel - { - return source.Draw(pen, shape, GraphicsOptions.Default); - } + where TPixel : struct, IPixel + => source.Draw(pen, shape, GraphicsOptions.Default); /// - /// Draws the outline of the polygon with the provided brush at the provided thickness. + /// Draws the outline of the rectangle with the provided brush at the provided thickness. /// /// The type of the color. /// The image this method extends. @@ -54,13 +50,11 @@ namespace SixLabors.ImageSharp /// The options. /// The . public static IImageProcessingContext Draw(this IImageProcessingContext source, IBrush brush, float thickness, RectangleF shape, GraphicsOptions options) - where TPixel : struct, IPixel - { - return source.Draw(new Pen(brush, thickness), shape, options); - } + where TPixel : struct, IPixel + => source.Draw(new Pen(brush, thickness), shape, options); /// - /// Draws the outline of the polygon with the provided brush at the provided thickness. + /// Draws the outline of the rectangle with the provided brush at the provided thickness. /// /// The type of the color. /// The image this method extends. @@ -69,13 +63,11 @@ namespace SixLabors.ImageSharp /// The shape. /// The . public static IImageProcessingContext Draw(this IImageProcessingContext source, IBrush brush, float thickness, RectangleF shape) - where TPixel : struct, IPixel - { - return source.Draw(new Pen(brush, thickness), shape); - } + where TPixel : struct, IPixel + => source.Draw(new Pen(brush, thickness), shape); /// - /// Draws the outline of the polygon with the provided brush at the provided thickness. + /// Draws the outline of the rectangle with the provided brush at the provided thickness. /// /// The type of the color. /// The image this method extends. @@ -85,13 +77,11 @@ namespace SixLabors.ImageSharp /// The options. /// The . public static IImageProcessingContext Draw(this IImageProcessingContext source, TPixel color, float thickness, RectangleF shape, GraphicsOptions options) - where TPixel : struct, IPixel - { - return source.Draw(new SolidBrush(color), thickness, shape, options); - } + where TPixel : struct, IPixel + => source.Draw(new SolidBrush(color), thickness, shape, options); /// - /// Draws the outline of the polygon with the provided brush at the provided thickness. + /// Draws the outline of the rectangle with the provided brush at the provided thickness. /// /// The type of the color. /// The image this method extends. @@ -100,9 +90,7 @@ namespace SixLabors.ImageSharp /// The shape. /// The . public static IImageProcessingContext Draw(this IImageProcessingContext source, TPixel color, float thickness, RectangleF shape) - where TPixel : struct, IPixel - { - return source.Draw(new SolidBrush(color), thickness, shape); - } + where TPixel : struct, IPixel + => source.Draw(new SolidBrush(color), thickness, shape); } -} +} \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Paths/FillPathBuilder.cs b/src/ImageSharp.Drawing/Processing/Drawing/FillPathBuilderExtensions.cs similarity index 79% rename from src/ImageSharp.Drawing/Paths/FillPathBuilder.cs rename to src/ImageSharp.Drawing/Processing/Drawing/FillPathBuilderExtensions.cs index fff082f2d9..975b5db4c6 100644 --- a/src/ImageSharp.Drawing/Paths/FillPathBuilder.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/FillPathBuilderExtensions.cs @@ -2,20 +2,19 @@ // Licensed under the Apache License, Version 2.0. using System; -using SixLabors.ImageSharp.Drawing; -using SixLabors.ImageSharp.Drawing.Brushes; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Drawing.Brushes; using SixLabors.Shapes; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Drawing { /// - /// Extension methods for the type. + /// Adds extensions that allow the filling of polygons with various brushes to the type. /// - public static partial class ImageExtensions + public static class FillPathBuilderExtensions { /// - /// Flood fills the image in the shape of the provided polygon with the specified brush.. + /// Flood fills the image in the shape of the provided polygon with the specified brush. /// /// The type of the color. /// The image this method extends. @@ -41,13 +40,11 @@ namespace SixLabors.ImageSharp /// The path. /// The . public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, Action path) - where TPixel : struct, IPixel - { - return source.Fill(brush, path, GraphicsOptions.Default); - } + where TPixel : struct, IPixel + => source.Fill(brush, path, GraphicsOptions.Default); /// - /// Flood fills the image in the shape of the provided polygon with the specified brush.. + /// Flood fills the image in the shape of the provided polygon with the specified brush. /// /// The type of the color. /// The image this method extends. @@ -56,13 +53,11 @@ namespace SixLabors.ImageSharp /// The options. /// The . public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, Action path, GraphicsOptions options) - where TPixel : struct, IPixel - { - return source.Fill(new SolidBrush(color), path, options); - } + where TPixel : struct, IPixel + => source.Fill(new SolidBrush(color), path, options); /// - /// Flood fills the image in the shape of the provided polygon with the specified brush.. + /// Flood fills the image in the shape of the provided polygon with the specified brush. /// /// The type of the color. /// The image this method extends. @@ -70,9 +65,7 @@ namespace SixLabors.ImageSharp /// The path. /// The . public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, Action path) - where TPixel : struct, IPixel - { - return source.Fill(new SolidBrush(color), path); - } + where TPixel : struct, IPixel + => source.Fill(new SolidBrush(color), path); } -} +} \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Paths/FillPathCollection.cs b/src/ImageSharp.Drawing/Processing/Drawing/FillPathCollectionExtensions.cs similarity index 79% rename from src/ImageSharp.Drawing/Paths/FillPathCollection.cs rename to src/ImageSharp.Drawing/Processing/Drawing/FillPathCollectionExtensions.cs index b252b95d5b..be472d373b 100644 --- a/src/ImageSharp.Drawing/Paths/FillPathCollection.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/FillPathCollectionExtensions.cs @@ -1,20 +1,19 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Drawing; -using SixLabors.ImageSharp.Drawing.Brushes; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Drawing.Brushes; using SixLabors.Shapes; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Drawing { /// - /// Extension methods for the type. + /// Adds extensions that allow the filling of collections of polygon outlines to the type. /// - public static partial class ImageExtensions + public static class FillPathCollectionExtensions { /// - /// Flood fills the image in the shape of the provided polygon with the specified brush.. + /// Flood fills the image in the shape of the provided polygon with the specified brush. /// /// The type of the color. /// The image this method extends. @@ -42,13 +41,11 @@ namespace SixLabors.ImageSharp /// The paths. /// The . public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, IPathCollection paths) - where TPixel : struct, IPixel - { - return source.Fill(brush, paths, GraphicsOptions.Default); - } + where TPixel : struct, IPixel + => source.Fill(brush, paths, GraphicsOptions.Default); /// - /// Flood fills the image in the shape of the provided polygon with the specified brush.. + /// Flood fills the image in the shape of the provided polygon with the specified brush. /// /// The type of the color. /// The image this method extends. @@ -57,13 +54,11 @@ namespace SixLabors.ImageSharp /// The options. /// The . public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, IPathCollection paths, GraphicsOptions options) - where TPixel : struct, IPixel - { - return source.Fill(new SolidBrush(color), paths, options); - } + where TPixel : struct, IPixel + => source.Fill(new SolidBrush(color), paths, options); /// - /// Flood fills the image in the shape of the provided polygon with the specified brush.. + /// Flood fills the image in the shape of the provided polygon with the specified brush. /// /// The type of the color. /// The image this method extends. @@ -71,9 +66,7 @@ namespace SixLabors.ImageSharp /// The paths. /// The . public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, IPathCollection paths) - where TPixel : struct, IPixel - { - return source.Fill(new SolidBrush(color), paths); - } + where TPixel : struct, IPixel + => source.Fill(new SolidBrush(color), paths); } -} +} \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Paths/FillPaths.cs b/src/ImageSharp.Drawing/Processing/Drawing/FillPathExtensions.cs similarity index 77% rename from src/ImageSharp.Drawing/Paths/FillPaths.cs rename to src/ImageSharp.Drawing/Processing/Drawing/FillPathExtensions.cs index f554ed7581..9b288c8bef 100644 --- a/src/ImageSharp.Drawing/Paths/FillPaths.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/FillPathExtensions.cs @@ -1,17 +1,17 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Drawing; -using SixLabors.ImageSharp.Drawing.Brushes; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Primitives; +using SixLabors.ImageSharp.Processing.Drawing.Brushes; using SixLabors.Shapes; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Drawing { /// - /// Extension methods for the type. + /// Adds extensions that allow the filling of polygon outlines to the type. /// - public static partial class ImageExtensions + public static class FillPathExtensions { /// /// Flood fills the image in the shape of the provided polygon with the specified brush.. @@ -23,10 +23,8 @@ namespace SixLabors.ImageSharp /// The graphics options. /// The . public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, IPath path, GraphicsOptions options) - where TPixel : struct, IPixel - { - return source.Fill(brush, new ShapeRegion(path), options); - } + where TPixel : struct, IPixel + => source.Fill(brush, new ShapeRegion(path), options); /// /// Flood fills the image in the shape of the provided polygon with the specified brush. @@ -37,10 +35,8 @@ namespace SixLabors.ImageSharp /// The path. /// The . public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, IPath path) - where TPixel : struct, IPixel - { - return source.Fill(brush, new ShapeRegion(path), GraphicsOptions.Default); - } + where TPixel : struct, IPixel + => source.Fill(brush, new ShapeRegion(path), GraphicsOptions.Default); /// /// Flood fills the image in the shape of the provided polygon with the specified brush.. @@ -52,10 +48,8 @@ namespace SixLabors.ImageSharp /// The options. /// The . public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, IPath path, GraphicsOptions options) - where TPixel : struct, IPixel - { - return source.Fill(new SolidBrush(color), path, options); - } + where TPixel : struct, IPixel + => source.Fill(new SolidBrush(color), path, options); /// /// Flood fills the image in the shape of the provided polygon with the specified brush.. @@ -66,9 +60,7 @@ namespace SixLabors.ImageSharp /// The path. /// The . public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, IPath path) - where TPixel : struct, IPixel - { - return source.Fill(new SolidBrush(color), path); - } + where TPixel : struct, IPixel + => source.Fill(new SolidBrush(color), path); } -} +} \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Paths/FillPolygon.cs b/src/ImageSharp.Drawing/Processing/Drawing/FillPolygonExtensions.cs similarity index 74% rename from src/ImageSharp.Drawing/Paths/FillPolygon.cs rename to src/ImageSharp.Drawing/Processing/Drawing/FillPolygonExtensions.cs index d8723bc31f..692f88337e 100644 --- a/src/ImageSharp.Drawing/Paths/FillPolygon.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/FillPolygonExtensions.cs @@ -1,20 +1,17 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; -using System.Numerics; -using SixLabors.ImageSharp.Drawing; -using SixLabors.ImageSharp.Drawing.Brushes; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Drawing.Brushes; using SixLabors.Primitives; using SixLabors.Shapes; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Drawing { /// - /// Extension methods for the type. + /// Adds extensions that allow the filling of closed linear polygons to the type. /// - public static partial class ImageExtensions + public static class FillPolygonExtensions { /// /// Flood fills the image in the shape of a Linear polygon described by the points @@ -26,10 +23,8 @@ namespace SixLabors.ImageSharp /// The options. /// The . public static IImageProcessingContext FillPolygon(this IImageProcessingContext source, IBrush brush, PointF[] points, GraphicsOptions options) - where TPixel : struct, IPixel - { - return source.Fill(brush, new Polygon(new LinearLineSegment(points)), options); - } + where TPixel : struct, IPixel + => source.Fill(brush, new Polygon(new LinearLineSegment(points)), options); /// /// Flood fills the image in the shape of a Linear polygon described by the points @@ -40,10 +35,8 @@ namespace SixLabors.ImageSharp /// The points. /// The . public static IImageProcessingContext FillPolygon(this IImageProcessingContext source, IBrush brush, PointF[] points) - where TPixel : struct, IPixel - { - return source.Fill(brush, new Polygon(new LinearLineSegment(points))); - } + where TPixel : struct, IPixel + => source.Fill(brush, new Polygon(new LinearLineSegment(points))); /// /// Flood fills the image in the shape of a Linear polygon described by the points @@ -55,10 +48,8 @@ namespace SixLabors.ImageSharp /// The options. /// The . public static IImageProcessingContext FillPolygon(this IImageProcessingContext source, TPixel color, PointF[] points, GraphicsOptions options) - where TPixel : struct, IPixel - { - return source.Fill(new SolidBrush(color), new Polygon(new LinearLineSegment(points)), options); - } + where TPixel : struct, IPixel + => source.Fill(new SolidBrush(color), new Polygon(new LinearLineSegment(points)), options); /// /// Flood fills the image in the shape of a Linear polygon described by the points @@ -69,9 +60,7 @@ namespace SixLabors.ImageSharp /// The points. /// The . public static IImageProcessingContext FillPolygon(this IImageProcessingContext source, TPixel color, PointF[] points) - where TPixel : struct, IPixel - { - return source.Fill(new SolidBrush(color), new Polygon(new LinearLineSegment(points))); - } + where TPixel : struct, IPixel + => source.Fill(new SolidBrush(color), new Polygon(new LinearLineSegment(points))); } -} +} \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Paths/FillRectangle.cs b/src/ImageSharp.Drawing/Processing/Drawing/FillRectangleExtensions.cs similarity index 68% rename from src/ImageSharp.Drawing/Paths/FillRectangle.cs rename to src/ImageSharp.Drawing/Processing/Drawing/FillRectangleExtensions.cs index 52578de178..eff333a4f2 100644 --- a/src/ImageSharp.Drawing/Paths/FillRectangle.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/FillRectangleExtensions.cs @@ -1,20 +1,20 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Drawing; -using SixLabors.ImageSharp.Drawing.Brushes; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Drawing.Brushes; using SixLabors.Primitives; +using SixLabors.Shapes; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Drawing { /// - /// Extension methods for the type. + /// Adds extensions that allow the filling of rectangles to the type. /// - public static partial class ImageExtensions + public static class FillRectangleExtensions { /// - /// Flood fills the image in the shape of the provided polygon with the specified brush.. + /// Flood fills the image in the shape of the provided rectangle with the specified brush. /// /// The type of the color. /// The image this method extends. @@ -24,12 +24,10 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, RectangleF shape, GraphicsOptions options) where TPixel : struct, IPixel - { - return source.Fill(brush, new SixLabors.Shapes.RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height), options); - } + => source.Fill(brush, new RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height), options); /// - /// Flood fills the image in the shape of the provided polygon with the specified brush.. + /// Flood fills the image in the shape of the provided rectangle with the specified brush. /// /// The type of the color. /// The image this method extends. @@ -38,12 +36,10 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, RectangleF shape) where TPixel : struct, IPixel - { - return source.Fill(brush, new SixLabors.Shapes.RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height)); - } + => source.Fill(brush, new RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height)); /// - /// Flood fills the image in the shape of the provided polygon with the specified brush.. + /// Flood fills the image in the shape of the provided rectangle with the specified brush. /// /// The type of the color. /// The image this method extends. @@ -52,13 +48,11 @@ namespace SixLabors.ImageSharp /// The options. /// The . public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, RectangleF shape, GraphicsOptions options) - where TPixel : struct, IPixel - { - return source.Fill(new SolidBrush(color), shape, options); - } + where TPixel : struct, IPixel + => source.Fill(new SolidBrush(color), shape, options); /// - /// Flood fills the image in the shape of the provided polygon with the specified brush.. + /// Flood fills the image in the shape of the provided rectangle with the specified brush. /// /// The type of the color. /// The image this method extends. @@ -67,8 +61,6 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, RectangleF shape) where TPixel : struct, IPixel - { - return source.Fill(new SolidBrush(color), shape); - } + => source.Fill(new SolidBrush(color), shape); } -} +} \ No newline at end of file diff --git a/src/ImageSharp.Drawing/FillRegion.cs b/src/ImageSharp.Drawing/Processing/Drawing/FillRegionExtensions.cs similarity index 79% rename from src/ImageSharp.Drawing/FillRegion.cs rename to src/ImageSharp.Drawing/Processing/Drawing/FillRegionExtensions.cs index 2e5d311c6d..d3e2232227 100644 --- a/src/ImageSharp.Drawing/FillRegion.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/FillRegionExtensions.cs @@ -1,32 +1,18 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Drawing; -using SixLabors.ImageSharp.Drawing.Brushes; -using SixLabors.ImageSharp.Drawing.Processors; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Primitives; +using SixLabors.ImageSharp.Processing.Drawing.Brushes; +using SixLabors.ImageSharp.Processing.Drawing.Processors; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Drawing { /// - /// Extension methods for the type. + /// Adds extensions that allow the filling of regions with various brushes to the type. /// - public static partial class ImageExtensions + public static class FillRegionExtensions { - /// - /// Flood fills the image with the specified brush. - /// - /// The type of the color. - /// The image this method extends. - /// The details how to fill the region of interest. - /// The graphics options. - /// The . - public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, GraphicsOptions options) - where TPixel : struct, IPixel - { - return source.ApplyProcessor(new FillProcessor(brush, options)); - } - /// /// Flood fills the image with the specified brush. /// @@ -36,9 +22,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush) where TPixel : struct, IPixel - { - return source.Fill(brush, GraphicsOptions.Default); - } + => source.Fill(brush, GraphicsOptions.Default); /// /// Flood fills the image with the specified color. @@ -49,9 +33,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color) where TPixel : struct, IPixel - { - return source.Fill(new SolidBrush(color)); - } + => source.Fill(new SolidBrush(color)); /// /// Flood fills the image with in the region with the specified brush. @@ -60,27 +42,23 @@ namespace SixLabors.ImageSharp /// The image this method extends. /// The brush. /// The region. - /// The graphics options. /// The . - public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, Region region, GraphicsOptions options) - where TPixel : struct, IPixel - { - return source.ApplyProcessor(new FillRegionProcessor(brush, region, options)); - } + public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, Region region) + where TPixel : struct, IPixel + => source.Fill(brush, region, GraphicsOptions.Default); /// - /// Flood fills the image with in the region with the specified brush. + /// Flood fills the image with in the region with the specified color. /// /// The type of the color. /// The image this method extends. - /// The brush. + /// The color. /// The region. + /// The options. /// The . - public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, Region region) - where TPixel : struct, IPixel - { - return source.Fill(brush, region, GraphicsOptions.Default); - } + public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, Region region, GraphicsOptions options) + where TPixel : struct, IPixel + => source.Fill(new SolidBrush(color), region, options); /// /// Flood fills the image with in the region with the specified color. @@ -89,26 +67,34 @@ namespace SixLabors.ImageSharp /// The image this method extends. /// The color. /// The region. - /// The options. /// The . - public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, Region region, GraphicsOptions options) - where TPixel : struct, IPixel - { - return source.Fill(new SolidBrush(color), region, options); - } + public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, Region region) + where TPixel : struct, IPixel + => source.Fill(new SolidBrush(color), region); /// - /// Flood fills the image with in the region with the specified color. + /// Flood fills the image with in the region with the specified brush. /// /// The type of the color. /// The image this method extends. - /// The color. + /// The brush. /// The region. + /// The graphics options. /// The . - public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, Region region) - where TPixel : struct, IPixel - { - return source.Fill(new SolidBrush(color), region); - } + public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, Region region, GraphicsOptions options) + where TPixel : struct, IPixel + => source.ApplyProcessor(new FillRegionProcessor(brush, region, options)); + + /// + /// Flood fills the image with the specified brush. + /// + /// The type of the color. + /// The image this method extends. + /// The details how to fill the region of interest. + /// The graphics options. + /// The . + public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, GraphicsOptions options) + where TPixel : struct, IPixel + => source.ApplyProcessor(new FillProcessor(brush, options)); } -} +} \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Pens/IPen.cs b/src/ImageSharp.Drawing/Processing/Drawing/Pens/IPen.cs similarity index 74% rename from src/ImageSharp.Drawing/Pens/IPen.cs rename to src/ImageSharp.Drawing/Processing/Drawing/Pens/IPen.cs index 0680ec2f56..387165e20c 100644 --- a/src/ImageSharp.Drawing/Pens/IPen.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Pens/IPen.cs @@ -1,11 +1,11 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Drawing.Brushes; -using SixLabors.ImageSharp.Drawing.Processors; +using System; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Drawing.Brushes; -namespace SixLabors.ImageSharp.Drawing.Pens +namespace SixLabors.ImageSharp.Processing.Drawing.Pens { /// /// Interface representing a Pen @@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Drawing.Pens } /// - /// Iterface represting the pattern and size of the stroke to apply with a Pen. + /// Interface representing the pattern and size of the stroke to apply with a Pen. /// public interface IPen { @@ -33,6 +33,6 @@ namespace SixLabors.ImageSharp.Drawing.Pens /// /// Gets the stoke pattern. /// - System.ReadOnlySpan StrokePattern { get; } + ReadOnlySpan StrokePattern { get; } } } diff --git a/src/ImageSharp.Drawing/Pens/Pens.cs b/src/ImageSharp.Drawing/Processing/Drawing/Pens/Pens.cs similarity index 90% rename from src/ImageSharp.Drawing/Pens/Pens.cs rename to src/ImageSharp.Drawing/Processing/Drawing/Pens/Pens.cs index 6478b1b813..b1883e3220 100644 --- a/src/ImageSharp.Drawing/Pens/Pens.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Pens/Pens.cs @@ -1,20 +1,21 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Drawing.Brushes; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Drawing.Brushes; -namespace SixLabors.ImageSharp.Drawing.Pens +namespace SixLabors.ImageSharp.Processing.Drawing.Pens { /// - /// Common Pen styles + /// Contains a collection of common Pen styles /// 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 }; + private static readonly float[] DashDotPattern = { 3f, 1f, 1f, 1f }; + private static readonly float[] DashDotDotPattern = { 3f, 1f, 1f, 1f, 1f, 1f }; + private static readonly float[] DottedPattern = { 1f, 1f }; + private static readonly float[] DashedPattern = { 3f, 1f }; + internal static readonly float[] EmptyPattern = new float[0]; /// /// Create a solid pen with out any drawing patterns diff --git a/src/ImageSharp.Drawing/Pens/Pen{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Drawing/Pens/Pen{TPixel}.cs similarity index 76% rename from src/ImageSharp.Drawing/Pens/Pen{TPixel}.cs rename to src/ImageSharp.Drawing/Processing/Drawing/Pens/Pen{TPixel}.cs index 74e4c6596d..1dd6b6616d 100644 --- a/src/ImageSharp.Drawing/Pens/Pen{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Pens/Pen{TPixel}.cs @@ -2,12 +2,10 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Numerics; -using SixLabors.ImageSharp.Drawing.Brushes; -using SixLabors.ImageSharp.Drawing.Processors; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Drawing.Brushes; -namespace SixLabors.ImageSharp.Drawing.Pens +namespace SixLabors.ImageSharp.Processing.Drawing.Pens { /// /// Provides a pen that can apply a pattern to a line with a set brush and thickness @@ -19,16 +17,15 @@ namespace SixLabors.ImageSharp.Drawing.Pens /// section 1 will be width long (making a square) and will be filled by the brush /// section 2 will be width * 2 long and will be empty /// section 3 will be width/2 long and will be filled - /// the the pattern will imidiatly repeat without gap. + /// the the pattern will immediately repeat without gap. /// public class Pen : IPen where TPixel : struct, IPixel { - private static readonly float[] EmptyPattern = new float[0]; private readonly float[] pattern; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The color. /// The width. @@ -39,7 +36,7 @@ namespace SixLabors.ImageSharp.Drawing.Pens } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The brush. /// The width. @@ -52,7 +49,7 @@ namespace SixLabors.ImageSharp.Drawing.Pens } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The color. /// The width. @@ -62,12 +59,12 @@ namespace SixLabors.ImageSharp.Drawing.Pens } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The brush. /// The width. public Pen(IBrush brush, float width) - : this(brush, width, EmptyPattern) + : this(brush, width, Pens.EmptyPattern) { } diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Processors/DrawImageProcessor.cs b/src/ImageSharp.Drawing/Processing/Drawing/Processors/DrawImageProcessor.cs new file mode 100644 index 0000000000..7b6e36d9d1 --- /dev/null +++ b/src/ImageSharp.Drawing/Processing/Drawing/Processors/DrawImageProcessor.cs @@ -0,0 +1,155 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Threading.Tasks; +using SixLabors.ImageSharp.Advanced; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; + +namespace SixLabors.ImageSharp.Processing.Drawing.Processors +{ + /// + /// Combines two images together by blending the pixels. + /// + /// The pixel format. + internal class DrawImageProcessor : ImageProcessor + where TPixel : struct, IPixel + { + /// + /// Initializes a new instance of the class. + /// + /// The image to blend with the currently processing image. + /// The opacity of the image to blend. Must be between 0 and 1. + public DrawImageProcessor(Image image, float opacity) + : this(image, Point.Empty, opacity) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The image to blend with the currently processing image. + /// + /// The options containing the opacity of the image to blend and blending mode. + /// Opacity must be between 0 and 1. + /// + public DrawImageProcessor(Image image, GraphicsOptions options) + : this(image, Point.Empty, options) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The image to blend with the currently processing image. + /// The location to draw the blended image. + /// The opacity of the image to blend. Must be between 0 and 1. + public DrawImageProcessor(Image image, Point location, float opacity) + : this(image, location, opacity, GraphicsOptions.Default.BlenderMode) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The image to blend with the currently processing image. + /// The location to draw the blended image. + /// + /// The options containing the opacity of the image to blend and blending mode. + /// Opacity must be between 0 and 1. + /// + public DrawImageProcessor(Image image, Point location, GraphicsOptions options) + : this(image, location, options.BlendPercentage, options.BlenderMode) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The image to blend with the currently processing image. + /// The opacity of the image to blend. Must be between 0 and 1. + /// The blending mode to use when drawing the image. + public DrawImageProcessor(Image image, float opacity, PixelBlenderMode blenderMode) + : this(image, Point.Empty, opacity, blenderMode) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The image to blend with the currently processing image. + /// The location to draw the blended image. + /// The opacity of the image to blend. Must be between 0 and 1. + /// The blending mode to use when drawing the image. + public DrawImageProcessor(Image image, Point location, float opacity, PixelBlenderMode blenderMode) + { + Guard.MustBeBetweenOrEqualTo(opacity, 0, 1, nameof(opacity)); + + this.Image = image; + this.Opacity = opacity; + this.Blender = PixelOperations.Instance.GetPixelBlender(blenderMode); + this.Location = location; + } + + /// + /// Gets the image to blend + /// + public Image Image { get; } + + /// + /// Gets the opacity of the image to blend + /// + public float Opacity { get; } + + /// + /// Gets the pixel blender + /// + public PixelBlender Blender { get; } + + /// + /// Gets the location to draw the blended image + /// + public Point Location { get; } + + /// + protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) + { + Image targetImage = this.Image; + PixelBlender blender = this.Blender; + int locationY = this.Location.Y; + + // Align start/end positions. + Rectangle bounds = targetImage.Bounds(); + + int minX = Math.Max(this.Location.X, sourceRectangle.X); + int maxX = Math.Min(this.Location.X + bounds.Width, sourceRectangle.Width); + int targetX = minX - this.Location.X; + + int minY = Math.Max(this.Location.Y, sourceRectangle.Y); + int maxY = Math.Min(this.Location.Y + bounds.Height, sourceRectangle.Bottom); + + int width = maxX - minX; + + MemoryManager memoryManager = this.Image.GetConfiguration().MemoryManager; + + using (IBuffer amount = memoryManager.Allocate(width)) + { + amount.Span.Fill(this.Opacity); + + Parallel.For( + minY, + maxY, + configuration.ParallelOptions, + y => + { + Span background = source.GetPixelRowSpan(y).Slice(minX, width); + Span foreground = targetImage.GetPixelRowSpan(y - locationY).Slice(targetX, width); + blender.Blend(memoryManager, background, background, foreground, amount.Span); + }); + } + } + } +} \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Processors/FillProcessor.cs b/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillProcessor.cs similarity index 84% rename from src/ImageSharp.Drawing/Processors/FillProcessor.cs rename to src/ImageSharp.Drawing/Processing/Drawing/Processors/FillProcessor.cs index 3bf18a37ba..e4ef44564e 100644 --- a/src/ImageSharp.Drawing/Processors/FillProcessor.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillProcessor.cs @@ -2,21 +2,17 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Numerics; using System.Threading.Tasks; -using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Drawing; -using SixLabors.ImageSharp.Drawing.Brushes; -using SixLabors.ImageSharp.Drawing.Brushes.Processors; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Drawing.Brushes; +using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Drawing.Processors +namespace SixLabors.ImageSharp.Processing.Drawing.Processors { /// - /// Using the bursh as a source of pixels colors blends the brush color with source. + /// Using the brush as a source of pixels colors blends the brush color with source. /// /// The pixel format. internal class FillProcessor : ImageProcessor @@ -40,7 +36,7 @@ namespace SixLabors.ImageSharp.Drawing.Processors } /// - protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) + protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { int startX = sourceRectangle.X; int endX = sourceRectangle.Right; diff --git a/src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs b/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs similarity index 94% rename from src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs rename to src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs index 076785526c..aa0b2e9b23 100644 --- a/src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs @@ -2,24 +2,21 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Buffers; -using System.Diagnostics; using System.Runtime.CompilerServices; -using SixLabors.ImageSharp.Drawing; -using SixLabors.ImageSharp.Drawing.Brushes; -using SixLabors.ImageSharp.Drawing.Brushes.Processors; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Primitives; +using SixLabors.ImageSharp.Processing.Drawing.Brushes; +using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Drawing.Processors +namespace SixLabors.ImageSharp.Processing.Drawing.Processors { /// - /// Usinf a brsuh and a shape fills shape with contents of brush the + /// Using a brush and a shape fills shape with contents of brush the /// /// The type of the color. - /// + /// internal class FillRegionProcessor : ImageProcessor where TPixel : struct, IPixel { @@ -58,7 +55,7 @@ namespace SixLabors.ImageSharp.Drawing.Processors public GraphicsOptions Options { get; } /// - protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) + protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { Region region = this.Region; Rectangle rect = region.Bounds; diff --git a/src/ImageSharp.Drawing/Text/DrawText.Path.cs b/src/ImageSharp.Drawing/Processing/Text/DrawTextExtensions.Path.cs similarity index 84% rename from src/ImageSharp.Drawing/Text/DrawText.Path.cs rename to src/ImageSharp.Drawing/Processing/Text/DrawTextExtensions.Path.cs index 274b592058..84bf26c517 100644 --- a/src/ImageSharp.Drawing/Text/DrawText.Path.cs +++ b/src/ImageSharp.Drawing/Processing/Text/DrawTextExtensions.Path.cs @@ -1,20 +1,19 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System.Numerics; using SixLabors.Fonts; -using SixLabors.ImageSharp.Drawing; -using SixLabors.ImageSharp.Drawing.Brushes; -using SixLabors.ImageSharp.Drawing.Pens; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Drawing; +using SixLabors.ImageSharp.Processing.Drawing.Brushes; +using SixLabors.ImageSharp.Processing.Drawing.Pens; using SixLabors.Shapes; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Text { /// - /// Extension methods for the type. + /// Adds extensions that allow the drawing of text along given paths to the type. /// - public static partial class ImageExtensions + public static partial class DrawTextExtensions { /// /// Draws the text onto the the image filled via the brush. @@ -29,10 +28,8 @@ namespace SixLabors.ImageSharp /// The . /// public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, TPixel color, IPath path) - where TPixel : struct, IPixel - { - return source.DrawText(text, font, color, path, TextGraphicsOptions.Default); - } + where TPixel : struct, IPixel + => source.DrawText(text, font, color, path, TextGraphicsOptions.Default); /// /// Draws the text onto the the image filled via the brush. @@ -48,10 +45,8 @@ namespace SixLabors.ImageSharp /// The . /// public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, TPixel color, IPath path, TextGraphicsOptions options) - where TPixel : struct, IPixel - { - return source.DrawText(text, font, Brushes.Solid(color), null, path, options); - } + where TPixel : struct, IPixel + => source.DrawText(text, font, Brushes.Solid(color), null, path, options); /// /// Draws the text onto the the image filled via the brush. @@ -66,10 +61,8 @@ namespace SixLabors.ImageSharp /// The . /// public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IBrush brush, IPath path) - where TPixel : struct, IPixel - { - return source.DrawText(text, font, brush, path, TextGraphicsOptions.Default); - } + where TPixel : struct, IPixel + => source.DrawText(text, font, brush, path, TextGraphicsOptions.Default); /// /// Draws the text onto the the image filled via the brush. @@ -85,10 +78,8 @@ namespace SixLabors.ImageSharp /// The . /// public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IBrush brush, IPath path, TextGraphicsOptions options) - where TPixel : struct, IPixel - { - return source.DrawText(text, font, brush, null, path, options); - } + where TPixel : struct, IPixel + => source.DrawText(text, font, brush, null, path, options); /// /// Draws the text onto the the image outlined via the pen. @@ -103,10 +94,8 @@ namespace SixLabors.ImageSharp /// The . /// public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IPen pen, IPath path) - where TPixel : struct, IPixel - { - return source.DrawText(text, font, pen, path, TextGraphicsOptions.Default); - } + where TPixel : struct, IPixel + => source.DrawText(text, font, pen, path, TextGraphicsOptions.Default); /// /// Draws the text onto the the image outlined via the pen. @@ -122,10 +111,8 @@ namespace SixLabors.ImageSharp /// The . /// public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IPen pen, IPath path, TextGraphicsOptions options) - where TPixel : struct, IPixel - { - return source.DrawText(text, font, null, pen, path, options); - } + where TPixel : struct, IPixel + => source.DrawText(text, font, null, pen, path, options); /// /// Draws the text onto the the image filled via the brush then outlined via the pen. @@ -141,10 +128,8 @@ namespace SixLabors.ImageSharp /// The . /// public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IBrush brush, IPen pen, IPath path) - where TPixel : struct, IPixel - { - return source.DrawText(text, font, brush, pen, path, TextGraphicsOptions.Default); - } + where TPixel : struct, IPixel + => source.DrawText(text, font, brush, pen, path, TextGraphicsOptions.Default); /// /// Draws the text onto the the image filled via the brush then outlined via the pen. @@ -191,4 +176,4 @@ namespace SixLabors.ImageSharp return source; } } -} +} \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Text/DrawText.cs b/src/ImageSharp.Drawing/Processing/Text/DrawTextExtensions.cs similarity index 83% rename from src/ImageSharp.Drawing/Text/DrawText.cs rename to src/ImageSharp.Drawing/Processing/Text/DrawTextExtensions.cs index c0105011e9..5731804aca 100644 --- a/src/ImageSharp.Drawing/Text/DrawText.cs +++ b/src/ImageSharp.Drawing/Processing/Text/DrawTextExtensions.cs @@ -1,21 +1,20 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System.Numerics; using SixLabors.Fonts; -using SixLabors.ImageSharp.Drawing; -using SixLabors.ImageSharp.Drawing.Brushes; -using SixLabors.ImageSharp.Drawing.Pens; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Drawing; +using SixLabors.ImageSharp.Processing.Drawing.Brushes; +using SixLabors.ImageSharp.Processing.Drawing.Pens; using SixLabors.Primitives; using SixLabors.Shapes; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Text { /// - /// Extension methods for the type. + /// Adds extensions that allow the drawing of text to the type. /// - public static partial class ImageExtensions + public static partial class DrawTextExtensions { private static readonly int DefaultTextDpi = 72; @@ -32,10 +31,8 @@ namespace SixLabors.ImageSharp /// The . /// public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, TPixel color, PointF location) - where TPixel : struct, IPixel - { - return source.DrawText(text, font, color, location, TextGraphicsOptions.Default); - } + where TPixel : struct, IPixel + => source.DrawText(text, font, color, location, TextGraphicsOptions.Default); /// /// Draws the text onto the the image filled via the brush. @@ -51,10 +48,8 @@ namespace SixLabors.ImageSharp /// The . /// public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, TPixel color, PointF location, TextGraphicsOptions options) - where TPixel : struct, IPixel - { - return source.DrawText(text, font, Brushes.Solid(color), null, location, options); - } + where TPixel : struct, IPixel + => source.DrawText(text, font, Brushes.Solid(color), null, location, options); /// /// Draws the text onto the the image filled via the brush. @@ -69,10 +64,8 @@ namespace SixLabors.ImageSharp /// The . /// public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IBrush brush, PointF location) - where TPixel : struct, IPixel - { - return source.DrawText(text, font, brush, location, TextGraphicsOptions.Default); - } + where TPixel : struct, IPixel + => source.DrawText(text, font, brush, location, TextGraphicsOptions.Default); /// /// Draws the text onto the the image filled via the brush. @@ -88,10 +81,8 @@ namespace SixLabors.ImageSharp /// The . /// public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IBrush brush, PointF location, TextGraphicsOptions options) - where TPixel : struct, IPixel - { - return source.DrawText(text, font, brush, null, location, options); - } + where TPixel : struct, IPixel + => source.DrawText(text, font, brush, null, location, options); /// /// Draws the text onto the the image outlined via the pen. @@ -106,10 +97,8 @@ namespace SixLabors.ImageSharp /// The . /// public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IPen pen, PointF location) - where TPixel : struct, IPixel - { - return source.DrawText(text, font, pen, location, TextGraphicsOptions.Default); - } + where TPixel : struct, IPixel + => source.DrawText(text, font, pen, location, TextGraphicsOptions.Default); /// /// Draws the text onto the the image outlined via the pen. @@ -125,10 +114,8 @@ namespace SixLabors.ImageSharp /// The . /// public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IPen pen, PointF location, TextGraphicsOptions options) - where TPixel : struct, IPixel - { - return source.DrawText(text, font, null, pen, location, options); - } + where TPixel : struct, IPixel + => source.DrawText(text, font, null, pen, location, options); /// /// Draws the text onto the the image filled via the brush then outlined via the pen. @@ -144,13 +131,11 @@ namespace SixLabors.ImageSharp /// The . /// public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IBrush brush, IPen pen, PointF location) - where TPixel : struct, IPixel - { - return source.DrawText(text, font, brush, pen, location, TextGraphicsOptions.Default); - } + where TPixel : struct, IPixel + => source.DrawText(text, font, brush, pen, location, TextGraphicsOptions.Default); /// - /// Draws the text onto the the image filled via the brush then outlined via the pen. + /// Draws the text using the default resolution of 72dpi onto the the image filled via the brush then outlined via the pen. /// /// The type of the color. /// The image this method extends. @@ -194,4 +179,4 @@ namespace SixLabors.ImageSharp return source; } } -} +} \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Text/TextGraphicsOptions.cs b/src/ImageSharp.Drawing/Processing/Text/TextGraphicsOptions.cs similarity index 96% rename from src/ImageSharp.Drawing/Text/TextGraphicsOptions.cs rename to src/ImageSharp.Drawing/Processing/Text/TextGraphicsOptions.cs index c230a8c79e..bba473ddb8 100644 --- a/src/ImageSharp.Drawing/Text/TextGraphicsOptions.cs +++ b/src/ImageSharp.Drawing/Processing/Text/TextGraphicsOptions.cs @@ -1,9 +1,10 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. + using SixLabors.Fonts; using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Drawing +namespace SixLabors.ImageSharp.Processing.Text { /// /// Options for influencing the drawing functions. @@ -29,8 +30,8 @@ namespace SixLabors.ImageSharp.Drawing private float wrapTextWidth; - private SixLabors.Fonts.HorizontalAlignment? horizontalAlignment; - private SixLabors.Fonts.VerticalAlignment? verticalAlignment; + private HorizontalAlignment? horizontalAlignment; + private VerticalAlignment? verticalAlignment; /// /// Initializes a new instance of the struct. diff --git a/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs b/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs deleted file mode 100644 index 632b4d449d..0000000000 --- a/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; -using System.Threading.Tasks; -using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Helpers; -using SixLabors.ImageSharp.Memory; -using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing; -using SixLabors.Primitives; - -namespace SixLabors.ImageSharp.Drawing.Processors -{ - /// - /// Combines two images together by blending the pixels. - /// - /// The pixel format. - internal class DrawImageProcessor : ImageProcessor - where TPixel : struct, IPixel - { - /// - /// Initializes a new instance of the class. - /// - /// The image to blend with the currently processing image. - /// The location to draw the blended image. - /// The opacity of the image to blend. Between 0 and 1. - public DrawImageProcessor(Image image, Point location, GraphicsOptions options) - { - Guard.MustBeBetweenOrEqualTo(options.BlendPercentage, 0, 1, nameof(options.BlendPercentage)); - - this.Image = image; - this.Opacity = options.BlendPercentage; - this.Blender = PixelOperations.Instance.GetPixelBlender(options.BlenderMode); - this.Location = location; - } - - /// - /// Gets the image to blend - /// - public Image Image { get; } - - /// - /// Gets the opacity of the image to blend - /// - public float Opacity { get; } - - /// - /// Gets the pixel blender - /// - public PixelBlender Blender { get; } - - /// - /// Gets the location to draw the blended image - /// - public Point Location { get; } - - /// - protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) - { - Image targetImage = this.Image; - PixelBlender blender = this.Blender; - int locationY = this.Location.Y; - - // Align start/end positions. - Rectangle bounds = targetImage.Bounds(); - - int minX = Math.Max(this.Location.X, sourceRectangle.X); - int maxX = Math.Min(this.Location.X + bounds.Width, sourceRectangle.Width); - int targetX = minX - this.Location.X; - - int minY = Math.Max(this.Location.Y, sourceRectangle.Y); - int maxY = Math.Min(this.Location.Y + bounds.Height, sourceRectangle.Bottom); - - int width = maxX - minX; - - MemoryManager memoryManager = this.Image.GetConfiguration().MemoryManager; - - using (IBuffer amount = memoryManager.Allocate(width)) - { - amount.Span.Fill(this.Opacity); - - Parallel.For( - minY, - maxY, - configuration.ParallelOptions, - y => - { - Span background = source.GetPixelRowSpan(y).Slice(minX, width); - Span foreground = targetImage.GetPixelRowSpan(y - locationY).Slice(targetX, width); - blender.Blend(memoryManager, background, background, foreground, amount.Span); - }); - } - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs index 24d2dd4cc4..cbd8db748f 100644 --- a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs +++ b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs @@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp.Advanced /// /// Returns a reference to the 0th element of the Pixel buffer, /// allowing direct manipulation of pixel data through unsafe operations. - /// The pixel buffer is a contigous memory area containing Width*Height TPixel elements layed out in row-major order. + /// The pixel buffer is a contiguous memory area containing Width*Height TPixel elements laid out in row-major order. /// /// The Pixel format. /// The source image frame diff --git a/src/ImageSharp/Advanced/IPixelSource.cs b/src/ImageSharp/Advanced/IPixelSource.cs index c9edf118c6..a321e877ba 100644 --- a/src/ImageSharp/Advanced/IPixelSource.cs +++ b/src/ImageSharp/Advanced/IPixelSource.cs @@ -1,10 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; -using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Memory; -using SixLabors.ImageSharp.MetaData; using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Advanced diff --git a/src/ImageSharp/ColorSpaces/Hsv.cs b/src/ImageSharp/ColorSpaces/Hsv.cs index 45ffd7f121..fdfbfe5dd1 100644 --- a/src/ImageSharp/ColorSpaces/Hsv.cs +++ b/src/ImageSharp/ColorSpaces/Hsv.cs @@ -6,6 +6,8 @@ using System.ComponentModel; using System.Numerics; using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.PixelFormats; + namespace SixLabors.ImageSharp.ColorSpaces { /// diff --git a/src/ImageSharp/ColorSpaces/Rgb.cs b/src/ImageSharp/ColorSpaces/Rgb.cs index 53fa6086df..ac86cfbf06 100644 --- a/src/ImageSharp/ColorSpaces/Rgb.cs +++ b/src/ImageSharp/ColorSpaces/Rgb.cs @@ -6,6 +6,8 @@ using System.ComponentModel; using System.Numerics; using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.PixelFormats; + namespace SixLabors.ImageSharp.ColorSpaces { /// diff --git a/src/ImageSharp/Common/Extensions/Vector4Extensions.cs b/src/ImageSharp/Common/Extensions/Vector4Extensions.cs index 8133ebb38e..88712a736f 100644 --- a/src/ImageSharp/Common/Extensions/Vector4Extensions.cs +++ b/src/ImageSharp/Common/Extensions/Vector4Extensions.cs @@ -5,6 +5,8 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.PixelFormats; + namespace SixLabors.ImageSharp { /// diff --git a/src/ImageSharp/Configuration.cs b/src/ImageSharp/Configuration.cs index d41e48678b..06c588af33 100644 --- a/src/ImageSharp/Configuration.cs +++ b/src/ImageSharp/Configuration.cs @@ -2,17 +2,18 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Collections.Concurrent; using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats.Bmp; using SixLabors.ImageSharp.Formats.Gif; using SixLabors.ImageSharp.Formats.Jpeg; using SixLabors.ImageSharp.Formats.Png; +#if !NETSTANDARD1_1 using SixLabors.ImageSharp.IO; +#endif using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.Processing; namespace SixLabors.ImageSharp { diff --git a/src/ImageSharp/Formats/Gif/GifEncoder.cs b/src/ImageSharp/Formats/Gif/GifEncoder.cs index b548098be3..ad3e85f92f 100644 --- a/src/ImageSharp/Formats/Gif/GifEncoder.cs +++ b/src/ImageSharp/Formats/Gif/GifEncoder.cs @@ -1,14 +1,11 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; -using System.Collections.Generic; using System.IO; using System.Text; - using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Quantizers; +using SixLabors.ImageSharp.Processing.Quantization; namespace SixLabors.ImageSharp.Formats.Gif { diff --git a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs index 13ca5f2c61..bdb228f520 100644 --- a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Buffers; using System.IO; using System.Linq; using System.Text; @@ -10,7 +9,7 @@ using SixLabors.ImageSharp.IO; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.MetaData; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Quantizers; +using SixLabors.ImageSharp.Processing.Quantization; namespace SixLabors.ImageSharp.Formats.Gif { @@ -106,7 +105,7 @@ namespace SixLabors.ImageSharp.Formats.Gif var pixelQuantizer = (IQuantizer)this.quantizer; // Quantize the image returning a palette. - QuantizedImage quantized = pixelQuantizer.Quantize(image.Frames.RootFrame, size); + QuantizedFrame quantized = pixelQuantizer.Quantize(image.Frames.RootFrame, size); int index = this.GetTransparentIndex(quantized); @@ -154,7 +153,7 @@ namespace SixLabors.ImageSharp.Formats.Gif /// /// The . /// - private int GetTransparentIndex(QuantizedImage quantized) + private int GetTransparentIndex(QuantizedFrame quantized) where TPixel : struct, IPixel { // Transparent pixels are much more likely to be found at the end of a palette @@ -347,7 +346,7 @@ namespace SixLabors.ImageSharp.Formats.Gif /// The pixel format. /// The to encode. /// The writer to write to the stream with. - private void WriteColorTable(QuantizedImage image, EndianBinaryWriter writer) + private void WriteColorTable(QuantizedFrame image, EndianBinaryWriter writer) where TPixel : struct, IPixel { // Grab the palette and write it to the stream. @@ -377,9 +376,9 @@ namespace SixLabors.ImageSharp.Formats.Gif /// Writes the image pixel data to the stream. /// /// The pixel format. - /// The containing indexed pixels. + /// The containing indexed pixels. /// The stream to write to. - private void WriteImageData(QuantizedImage image, EndianBinaryWriter writer) + private void WriteImageData(QuantizedFrame image, EndianBinaryWriter writer) where TPixel : struct, IPixel { using (var encoder = new LzwEncoder(this.memoryManager, image.Pixels, (byte)this.bitDepth)) diff --git a/src/ImageSharp/Formats/Gif/IGifEncoderOptions.cs b/src/ImageSharp/Formats/Gif/IGifEncoderOptions.cs index 374dea6595..a709b2b9d8 100644 --- a/src/ImageSharp/Formats/Gif/IGifEncoderOptions.cs +++ b/src/ImageSharp/Formats/Gif/IGifEncoderOptions.cs @@ -1,12 +1,8 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; -using System.Collections.Generic; -using System.IO; using System.Text; -using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Quantizers; +using SixLabors.ImageSharp.Processing.Quantization; namespace SixLabors.ImageSharp.Formats.Gif { @@ -38,6 +34,6 @@ namespace SixLabors.ImageSharp.Formats.Gif /// /// Gets the quantizer for reducing the color count. /// - IQuantizer Quantizer { get; } + IQuantizer Quantizer { get; } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromGrayScale.cs b/src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromGrayScale.cs index 5c720e61c3..4769bef1d7 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromGrayScale.cs +++ b/src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromGrayScale.cs @@ -8,10 +8,10 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder.ColorConverters { internal abstract partial class JpegColorConverter { - internal class FromGrayScale : ColorConverters.JpegColorConverter + internal class FromGrayscale : ColorConverters.JpegColorConverter { - public FromGrayScale() - : base(JpegColorSpace.GrayScale) + public FromGrayscale() + : base(JpegColorSpace.Grayscale) { } diff --git a/src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.cs b/src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.cs index 187b65f72b..4391be5484 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.cs +++ b/src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.cs @@ -20,7 +20,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder.ColorConverters /// private static readonly JpegColorConverter[] Converters = { - GetYCbCrConverter(), new FromYccK(), new FromCmyk(), new FromGrayScale(), new FromRgb() + GetYCbCrConverter(), new FromYccK(), new FromCmyk(), new FromGrayscale(), new FromRgb() }; /// diff --git a/src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegColorSpace.cs b/src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegColorSpace.cs index da353d2795..abc93727e1 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegColorSpace.cs +++ b/src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegColorSpace.cs @@ -7,7 +7,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder { Undefined = 0, - GrayScale, + Grayscale, Ycck, diff --git a/src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegImagePostProcessor.cs b/src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegImagePostProcessor.cs index 2adf3e02d0..483242c768 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegImagePostProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegImagePostProcessor.cs @@ -2,7 +2,6 @@ using System; using System.Linq; using System.Numerics; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Helpers; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; @@ -116,7 +115,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder } /// - /// Execute one step rocessing pixel rows into 'destination'. + /// Execute one step processing pixel rows into 'destination'. /// /// The pixel type /// The destination image. diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs index 6cc275d49d..d3d1efe7fd 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs @@ -640,7 +640,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort switch (remaining) { - case 6 + (3 * 1): // Grayscale image. + case 6 + (3 * 1): // grayscale image. this.ComponentCount = 1; break; case 6 + (3 * 3): // YCbCr or RGB image. @@ -767,7 +767,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort switch (this.ComponentCount) { case 1: - return JpegColorSpace.GrayScale; + return JpegColorSpace.Grayscale; case 3: if (!this.isAdobe || this.adobe.ColorTransform == OrigJpegConstants.Adobe.ColorTransformYCbCr) { @@ -790,7 +790,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort } throw new ImageFormatException($"Unsupported color mode. Max components 4; found {this.ComponentCount}." - + "JpegDecoder only supports YCbCr, RGB, YccK, CMYK and Grayscale color spaces."); + + "JpegDecoder only supports YCbCr, RGB, YccK, CMYK and grayscale color spaces."); } private Image PostProcessIntoImage() diff --git a/src/ImageSharp/Formats/Jpeg/JpegEncoder.cs b/src/ImageSharp/Formats/Jpeg/JpegEncoder.cs index 8850f581c1..60b00c0f5b 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegEncoder.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegEncoder.cs @@ -20,6 +20,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg /// /// Gets or sets the quality, that will be used to encode the image. Quality /// index must be between 0 and 100 (compression from max to min). + /// Defaults to 75. /// public int Quality { get; set; } = 75; diff --git a/src/ImageSharp/Formats/Png/IPngEncoderOptions.cs b/src/ImageSharp/Formats/Png/IPngEncoderOptions.cs index 6b4b05e311..28020f2600 100644 --- a/src/ImageSharp/Formats/Png/IPngEncoderOptions.cs +++ b/src/ImageSharp/Formats/Png/IPngEncoderOptions.cs @@ -1,15 +1,12 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System.Collections.Generic; -using System.IO; -using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Quantizers; +using SixLabors.ImageSharp.Processing.Quantization; namespace SixLabors.ImageSharp.Formats.Png { /// - /// The options availible for manipulating the encoder pipeline + /// The options available for manipulating the encoder pipeline /// internal interface IPngEncoderOptions { diff --git a/src/ImageSharp/Formats/Png/PngDecoder.cs b/src/ImageSharp/Formats/Png/PngDecoder.cs index 9bde4f8cc3..57d45ecddb 100644 --- a/src/ImageSharp/Formats/Png/PngDecoder.cs +++ b/src/ImageSharp/Formats/Png/PngDecoder.cs @@ -20,8 +20,8 @@ namespace SixLabors.ImageSharp.Formats.Png /// /// RGBA (True color) with alpha (8 bit). /// RGB (True color) without alpha (8 bit). - /// Grayscale with alpha (8 bit). - /// Grayscale without alpha (8 bit). + /// grayscale with alpha (8 bit). + /// grayscale without alpha (8 bit). /// Palette Index with alpha (8 bit). /// Palette Index without alpha (8 bit). /// diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index 1d1db2787a..dba4eaa15c 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -170,7 +170,7 @@ namespace SixLabors.ImageSharp.Formats.Png private Rgb24 rgb24Trans; /// - /// Represents any color in a Grayscale encoded png that should be transparent + /// Represents any color in a grayscale encoded png that should be transparent /// private byte intensityTrans; diff --git a/src/ImageSharp/Formats/Png/PngEncoder.cs b/src/ImageSharp/Formats/Png/PngEncoder.cs index 0c40ccf2a0..2cff18410d 100644 --- a/src/ImageSharp/Formats/Png/PngEncoder.cs +++ b/src/ImageSharp/Formats/Png/PngEncoder.cs @@ -3,9 +3,8 @@ using System.IO; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Quantizers; +using SixLabors.ImageSharp.Processing.Quantization; namespace SixLabors.ImageSharp.Formats.Png { diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index 1ab7a83ce0..29c9d2a142 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Buffers; using System.IO; using System.Linq; using SixLabors.ImageSharp.Advanced; @@ -10,7 +9,7 @@ using SixLabors.ImageSharp.Formats.Png.Filters; using SixLabors.ImageSharp.Formats.Png.Zlib; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Quantizers; +using SixLabors.ImageSharp.Processing.Quantization; namespace SixLabors.ImageSharp.Formats.Png { @@ -308,7 +307,7 @@ namespace SixLabors.ImageSharp.Formats.Png where TPixel : struct, IPixel { // Quantize the image and get the pixels. - QuantizedImage quantized = this.WritePaletteChunk(stream, header, image); + QuantizedFrame quantized = this.WritePaletteChunk(stream, header, image); this.palettePixelData = quantized.Pixels; } @@ -498,8 +497,8 @@ namespace SixLabors.ImageSharp.Formats.Png /// The containing image data. /// The . /// The image to encode. - /// The - private QuantizedImage WritePaletteChunk(Stream stream, PngHeader header, ImageFrame image) + /// The + private QuantizedFrame WritePaletteChunk(Stream stream, PngHeader header, ImageFrame image) where TPixel : struct, IPixel { if (this.paletteSize > 256) @@ -513,7 +512,7 @@ namespace SixLabors.ImageSharp.Formats.Png } // Quantize the image returning a palette. This boxing is icky. - QuantizedImage quantized = ((IQuantizer)this.quantizer).Quantize(image, this.paletteSize); + QuantizedFrame quantized = ((IQuantizer)this.quantizer).Quantize(image, this.paletteSize); // Grab the palette and write it to the stream. TPixel[] palette = quantized.Palette; diff --git a/src/ImageSharp/Helpers/ImageExtensions.cs b/src/ImageSharp/Helpers/ImageExtensions.cs deleted file mode 100644 index dbf2e34a42..0000000000 --- a/src/ImageSharp/Helpers/ImageExtensions.cs +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; -using System.Collections.Generic; -using System.IO; -using System.Runtime.CompilerServices; -using System.Text; -using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Formats; -using SixLabors.ImageSharp.PixelFormats; -using SixLabors.Primitives; - -namespace SixLabors.ImageSharp.Helpers -{ - /// - /// Extension methods over Image{TPixel} - /// - public static partial class ImageExtensions - { - /// - /// Gets the bounds of the image. - /// - /// The Pixel format. - /// The source image - /// Returns the bounds of the image - public static Rectangle Bounds(this Image source) - where TPixel : struct, IPixel - => new Rectangle(0, 0, source.Width, source.Height); - - /// - /// Gets the bounds of the image. - /// - /// The Pixel format. - /// The source image - /// Returns the bounds of the image - public static Rectangle Bounds(this ImageFrame source) - where TPixel : struct, IPixel - => new Rectangle(0, 0, source.Width, source.Height); - - /// - /// Gets the size of the image. - /// - /// The Pixel format. - /// The source image - /// Returns the bounds of the image - public static Size Size(this Image source) - where TPixel : struct, IPixel - => new Size(source.Width, source.Height); - - /// - /// Gets the size of the image. - /// - /// The Pixel format. - /// The source image - /// Returns the bounds of the image - public static Size Size(this ImageFrame source) - where TPixel : struct, IPixel - => new Size(source.Width, source.Height); - } -} diff --git a/src/ImageSharp/Image/IImage.cs b/src/ImageSharp/IImage.cs similarity index 100% rename from src/ImageSharp/Image/IImage.cs rename to src/ImageSharp/IImage.cs diff --git a/src/ImageSharp/Image/IImageFrameCollection.cs b/src/ImageSharp/IImageFrameCollection.cs similarity index 100% rename from src/ImageSharp/Image/IImageFrameCollection.cs rename to src/ImageSharp/IImageFrameCollection.cs diff --git a/src/ImageSharp/Image/IImageInfo.cs b/src/ImageSharp/IImageInfo.cs similarity index 100% rename from src/ImageSharp/Image/IImageInfo.cs rename to src/ImageSharp/IImageInfo.cs diff --git a/src/ImageSharp/Image/Image.Decode.cs b/src/ImageSharp/Image.Decode.cs similarity index 100% rename from src/ImageSharp/Image/Image.Decode.cs rename to src/ImageSharp/Image.Decode.cs diff --git a/src/ImageSharp/Image/Image.FromBytes.cs b/src/ImageSharp/Image.FromBytes.cs similarity index 100% rename from src/ImageSharp/Image/Image.FromBytes.cs rename to src/ImageSharp/Image.FromBytes.cs diff --git a/src/ImageSharp/Image/Image.FromFile.cs b/src/ImageSharp/Image.FromFile.cs similarity index 100% rename from src/ImageSharp/Image/Image.FromFile.cs rename to src/ImageSharp/Image.FromFile.cs diff --git a/src/ImageSharp/Image/Image.FromStream.cs b/src/ImageSharp/Image.FromStream.cs similarity index 100% rename from src/ImageSharp/Image/Image.FromStream.cs rename to src/ImageSharp/Image.FromStream.cs diff --git a/src/ImageSharp/Image/Image.LoadPixelData.cs b/src/ImageSharp/Image.LoadPixelData.cs similarity index 100% rename from src/ImageSharp/Image/Image.LoadPixelData.cs rename to src/ImageSharp/Image.LoadPixelData.cs diff --git a/src/ImageSharp/Image/ImageExtensions.cs b/src/ImageSharp/ImageExtensions.cs similarity index 100% rename from src/ImageSharp/Image/ImageExtensions.cs rename to src/ImageSharp/ImageExtensions.cs diff --git a/src/ImageSharp/Image/ImageFrame.LoadPixelData.cs b/src/ImageSharp/ImageFrame.LoadPixelData.cs similarity index 100% rename from src/ImageSharp/Image/ImageFrame.LoadPixelData.cs rename to src/ImageSharp/ImageFrame.LoadPixelData.cs diff --git a/src/ImageSharp/Image/ImageFrameCollection.cs b/src/ImageSharp/ImageFrameCollection.cs similarity index 97% rename from src/ImageSharp/Image/ImageFrameCollection.cs rename to src/ImageSharp/ImageFrameCollection.cs index aefeacce15..e85e67c741 100644 --- a/src/ImageSharp/Image/ImageFrameCollection.cs +++ b/src/ImageSharp/ImageFrameCollection.cs @@ -10,7 +10,7 @@ using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp { /// - /// Encapsulates an imaged collection of frames. + /// Encapsulates a collection of frames that make up an image. /// /// The type of the pixel. internal sealed class ImageFrameCollection : IImageFrameCollection @@ -51,10 +51,7 @@ namespace SixLabors.ImageSharp public ImageFrame RootFrame => this.frames.Count > 0 ? this.frames[0] : null; /// - public ImageFrame this[int index] - { - get => this.frames[index]; - } + public ImageFrame this[int index] => this.frames[index]; /// public int IndexOf(ImageFrame frame) => this.frames.IndexOf(frame); diff --git a/src/ImageSharp/Image/ImageFrame{TPixel}.cs b/src/ImageSharp/ImageFrame{TPixel}.cs similarity index 94% rename from src/ImageSharp/Image/ImageFrame{TPixel}.cs rename to src/ImageSharp/ImageFrame{TPixel}.cs index 833a22f7c7..888aff905e 100644 --- a/src/ImageSharp/Image/ImageFrame{TPixel}.cs +++ b/src/ImageSharp/ImageFrame{TPixel}.cs @@ -2,12 +2,10 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Diagnostics; using System.Numerics; using System.Runtime.CompilerServices; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Helpers; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.MetaData; using SixLabors.ImageSharp.PixelFormats; @@ -104,7 +102,7 @@ namespace SixLabors.ImageSharp /// /// Gets the meta data of the frame. /// - public ImageFrameMetaData MetaData { get; private set; } + public ImageFrameMetaData MetaData { get; } /// /// Gets or sets the pixel at the specified position. @@ -127,6 +125,18 @@ namespace SixLabors.ImageSharp } } + /// + /// Gets the size of the frame. + /// + /// The + public Size Size() => new Size(this.Width, this.Height); + + /// + /// Gets the bounds of the frame. + /// + /// The + public Rectangle Bounds() => new Rectangle(0, 0, this.Width, this.Height); + /// /// Gets a reference to the pixel at the specified position. /// @@ -168,7 +178,7 @@ namespace SixLabors.ImageSharp { if (this.Size() != target.Size()) { - throw new ArgumentException("ImageFrame.CopyTo(): target must be of the same size!", nameof(target)); + throw new ArgumentException("ImageFrame.CopyTo(): target must be of the same size!", nameof(target)); } SpanHelper.Copy(this.GetPixelSpan(), target.Span); diff --git a/src/ImageSharp/Image/ImageInfo.cs b/src/ImageSharp/ImageInfo.cs similarity index 100% rename from src/ImageSharp/Image/ImageInfo.cs rename to src/ImageSharp/ImageInfo.cs diff --git a/src/ImageSharp/ImageInfoExtensions.cs b/src/ImageSharp/ImageInfoExtensions.cs new file mode 100644 index 0000000000..0f2b2ba975 --- /dev/null +++ b/src/ImageSharp/ImageInfoExtensions.cs @@ -0,0 +1,27 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.Primitives; + +namespace SixLabors.ImageSharp +{ + /// + /// Extension methods that allow the addition of geometry calculating methods to the type + /// + public static class ImageInfoExtensions + { + /// + /// Gets the bounds of the image. + /// + /// The image info + /// The + public static Size Size(this IImageInfo info) => new Size(info.Width, info.Height); + + /// + /// Gets the bounds of the image. + /// + /// The image info + /// The + public static Rectangle Bounds(this IImageInfo info) => new Rectangle(0, 0, info.Width, info.Height); + } +} diff --git a/src/ImageSharp/ImageSharp.csproj b/src/ImageSharp/ImageSharp.csproj index 86a0ab7ea5..4433836793 100644 --- a/src/ImageSharp/ImageSharp.csproj +++ b/src/ImageSharp/ImageSharp.csproj @@ -37,7 +37,7 @@ - + All @@ -126,7 +126,4 @@ PorterDuffFunctions.Generated.tt - - - \ No newline at end of file diff --git a/src/ImageSharp/Image/Image{TPixel}.cs b/src/ImageSharp/Image{TPixel}.cs similarity index 96% rename from src/ImageSharp/Image/Image{TPixel}.cs rename to src/ImageSharp/Image{TPixel}.cs index f264d8a59d..78a091e414 100644 --- a/src/ImageSharp/Image/Image{TPixel}.cs +++ b/src/ImageSharp/Image{TPixel}.cs @@ -17,11 +17,11 @@ namespace SixLabors.ImageSharp /// Encapsulates an image, which consists of the pixel data for a graphics image and its attributes. /// /// The pixel format. - public sealed partial class Image : IImage, IConfigurable + public sealed class Image : IImage, IConfigurable where TPixel : struct, IPixel { - private Configuration configuration; - private ImageFrameCollection frames; + private readonly Configuration configuration; + private readonly ImageFrameCollection frames; /// /// Initializes a new instance of the class @@ -44,7 +44,7 @@ namespace SixLabors.ImageSharp /// The width of the image in pixels. /// The height of the image in pixels. public Image(int width, int height) - : this(null, width, height) + : this(Configuration.Default, width, height) { } @@ -97,7 +97,7 @@ namespace SixLabors.ImageSharp public int Height => this.frames.RootFrame.Height; /// - public ImageMetaData MetaData { get; private set; } = new ImageMetaData(); + public ImageMetaData MetaData { get; } /// /// Gets the frames. diff --git a/src/ImageSharp/Memory/ArrayPoolMemoryManager.CommonFactoryMethods.cs b/src/ImageSharp/Memory/ArrayPoolMemoryManager.CommonFactoryMethods.cs index d1424870da..53d7fc0216 100644 --- a/src/ImageSharp/Memory/ArrayPoolMemoryManager.CommonFactoryMethods.cs +++ b/src/ImageSharp/Memory/ArrayPoolMemoryManager.CommonFactoryMethods.cs @@ -1,4 +1,6 @@ -namespace SixLabors.ImageSharp.Memory +using SixLabors.ImageSharp.PixelFormats; + +namespace SixLabors.ImageSharp.Memory { /// /// Contains common factory methods and configuration constants. diff --git a/src/ImageSharp/Memory/Fast2DArray{T}.cs b/src/ImageSharp/Memory/Fast2DArray{T}.cs deleted file mode 100644 index 38ccdd279d..0000000000 --- a/src/ImageSharp/Memory/Fast2DArray{T}.cs +++ /dev/null @@ -1,173 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace SixLabors.ImageSharp.Memory -{ - /// - /// Provides fast access to 2D arrays. - /// - /// The type of elements in the array. - internal struct Fast2DArray - { - /// - /// The 1D representation of the 2D array. - /// - public T[] Data; - - /// - /// Gets the width of the 2D array. - /// - public int Width; - - /// - /// Gets the height of the 2D array. - /// - public int Height; - - /// - /// Gets the number of items in the 2D array - /// - public int Count; - - /// - /// Initializes a new instance of the struct. - /// - /// The length of each dimension. - public Fast2DArray(int length) - : this(length, length) - { - } - - /// - /// Initializes a new instance of the struct. - /// - /// The width. - /// The height. - public Fast2DArray(int width, int height) - { - this.Height = height; - this.Width = width; - - Guard.MustBeGreaterThan(width, 0, nameof(width)); - Guard.MustBeGreaterThan(height, 0, nameof(height)); - - this.Count = width * height; - this.Data = new T[this.Count]; - } - - /// - /// Initializes a new instance of the struct. - /// - /// The 2D array to provide access to. - public Fast2DArray(T[,] data) - { - Guard.NotNull(data, nameof(data)); - this.Height = data.GetLength(0); - this.Width = data.GetLength(1); - - Guard.MustBeGreaterThan(this.Width, 0, nameof(this.Width)); - Guard.MustBeGreaterThan(this.Height, 0, nameof(this.Height)); - - this.Count = this.Width * this.Height; - this.Data = new T[this.Count]; - - for (int y = 0; y < this.Height; y++) - { - for (int x = 0; x < this.Width; x++) - { - this.Data[(y * this.Width) + x] = data[y, x]; - } - } - } - - /// - /// Gets or sets the item at the specified position. - /// - /// The row-coordinate of the item. Must be greater than or equal to zero and less than the height of the array. - /// The column-coordinate of the item. Must be greater than or equal to zero and less than the width of the array. - /// The at the specified position. - public T this[int row, int column] - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - this.CheckCoordinates(row, column); - return this.Data[(row * this.Width) + column]; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - set - { - this.CheckCoordinates(row, column); - this.Data[(row * this.Width) + column] = value; - } - } - - /// - /// Performs an implicit conversion from a 2D array to a . - /// - /// The source array. - /// - /// The representation on the source data. - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static implicit operator Fast2DArray(T[,] data) - { - return new Fast2DArray(data); - } - - /// - /// Gets a representing the row beginning from the the first item on that row. - /// - /// The y-coordinate of the row. Must be greater than or equal to zero and less than the height of the 2D array. - /// The - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Span GetRowSpan(int row) - { - this.CheckCoordinates(row); - return new Span(this.Data, row * this.Width, this.Width); - } - - /// - /// Checks the coordinates to ensure they are within bounds. - /// - /// The y-coordinate of the item. Must be greater than zero and smaller than the height of the array. - /// The x-coordinate of the item. Must be greater than zero and smaller than the width of the array. - /// - /// Thrown if the coordinates are not within the bounds of the array. - /// - [Conditional("DEBUG")] - private void CheckCoordinates(int row, int column) - { - if (row < 0 || row >= this.Height) - { - throw new ArgumentOutOfRangeException(nameof(row), row, $"{row} is outwith the array bounds."); - } - - if (column < 0 || column >= this.Width) - { - throw new ArgumentOutOfRangeException(nameof(column), column, $"{column} is outwith the array bounds."); - } - } - - /// - /// Checks the coordinates to ensure they are within bounds. - /// - /// The y-coordinate of the item. Must be greater than zero and smaller than the height of the array. - /// - /// Thrown if the coordinates are not within the bounds of the image. - /// - [Conditional("DEBUG")] - private void CheckCoordinates(int row) - { - if (row < 0 || row >= this.Height) - { - throw new ArgumentOutOfRangeException(nameof(row), row, $"{row} is outwith the array bounds."); - } - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/MetaData/ImageMetaData.cs b/src/ImageSharp/MetaData/ImageMetaData.cs index e36f2a69f2..9613e9b465 100644 --- a/src/ImageSharp/MetaData/ImageMetaData.cs +++ b/src/ImageSharp/MetaData/ImageMetaData.cs @@ -2,8 +2,6 @@ // Licensed under the Apache License, Version 2.0. using System.Collections.Generic; -using SixLabors.ImageSharp.Formats; -using SixLabors.ImageSharp.Formats.Gif; using SixLabors.ImageSharp.MetaData.Profiles.Exif; using SixLabors.ImageSharp.MetaData.Profiles.Icc; diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Matrix.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Matrix.cs index 0b7064cf93..5d7d729b2c 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Matrix.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Matrix.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System.Numerics; -using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.Primitives; namespace SixLabors.ImageSharp.MetaData.Profiles.Icc { @@ -59,12 +59,12 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// The matrix to write /// True if the values are encoded as Single; false if encoded as Fix16 /// The number of bytes written - public int WriteMatrix(Fast2DArray value, bool isSingle) + public int WriteMatrix(DenseMatrix value, bool isSingle) { int count = 0; - for (int y = 0; y < value.Height; y++) + for (int y = 0; y < value.Rows; y++) { - for (int x = 0; x < value.Width; x++) + for (int x = 0; x < value.Columns; x++) { if (isSingle) { diff --git a/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccMatrixProcessElement.cs b/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccMatrixProcessElement.cs index 642f766d56..13b58161c6 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccMatrixProcessElement.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccMatrixProcessElement.cs @@ -3,7 +3,8 @@ using System; using System.Linq; -using SixLabors.ImageSharp.Memory; + +using SixLabors.ImageSharp.Primitives; namespace SixLabors.ImageSharp.MetaData.Profiles.Icc { @@ -33,7 +34,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// /// Gets the two dimensional matrix with size of Input-Channels x Output-Channels /// - public Fast2DArray MatrixIxO { get; } + public DenseMatrix MatrixIxO { get; } /// /// Gets the one dimensional matrix with size of Output-Channels x 1 @@ -60,18 +61,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc private bool EqualsMatrix(IccMatrixProcessElement element) { - for (int x = 0; x < this.MatrixIxO.Width; x++) - { - for (int y = 0; y < this.MatrixIxO.Height; y++) - { - if (this.MatrixIxO[x, y] != element.MatrixIxO[x, y]) - { - return false; - } - } - } - - return true; + return this.MatrixIxO.Equals(element.MatrixIxO); } } } diff --git a/src/ImageSharp/Image/PixelAccessorExtensions.cs b/src/ImageSharp/PixelAccessorExtensions.cs similarity index 100% rename from src/ImageSharp/Image/PixelAccessorExtensions.cs rename to src/ImageSharp/PixelAccessorExtensions.cs diff --git a/src/ImageSharp/Image/PixelAccessor{TPixel}.cs b/src/ImageSharp/PixelAccessor{TPixel}.cs similarity index 100% rename from src/ImageSharp/Image/PixelAccessor{TPixel}.cs rename to src/ImageSharp/PixelAccessor{TPixel}.cs diff --git a/src/ImageSharp/PixelFormats/Generated/Rgba32.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/Generated/Rgba32.PixelOperations.Generated.cs index edf6a88e1f..c5ee6661f7 100644 --- a/src/ImageSharp/PixelFormats/Generated/Rgba32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/Generated/Rgba32.PixelOperations.Generated.cs @@ -2,19 +2,18 @@ // Licensed under the Apache License, Version 2.0. // -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.PixelFormats { using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; - using SixLabors.ImageSharp.PixelFormats; /// /// Provides optimized overrides for bulk operations. /// public partial struct Rgba32 { - internal partial class PixelOperations : PixelOperations + internal partial class PixelOperations { /// diff --git a/src/ImageSharp/PixelFormats/Generated/Rgba32.PixelOperations.Generated.tt b/src/ImageSharp/PixelFormats/Generated/Rgba32.PixelOperations.Generated.tt index d83e49f770..9dfec2cf90 100644 --- a/src/ImageSharp/PixelFormats/Generated/Rgba32.PixelOperations.Generated.tt +++ b/src/ImageSharp/PixelFormats/Generated/Rgba32.PixelOperations.Generated.tt @@ -57,19 +57,18 @@ // Licensed under the Apache License, Version 2.0. // -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.PixelFormats { using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; - using SixLabors.ImageSharp.PixelFormats; /// /// Provides optimized overrides for bulk operations. /// public partial struct Rgba32 { - internal partial class PixelOperations : PixelOperations + internal partial class PixelOperations { <# GeneratePackFromMethod("Rgb24", "Unsafe.As(ref dp) = sp; dp.A = 255;"); diff --git a/src/ImageSharp/PixelFormats/PixelBlenderMode.cs b/src/ImageSharp/PixelFormats/PixelBlenderMode.cs index ae70cdee43..7541be7893 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenderMode.cs +++ b/src/ImageSharp/PixelFormats/PixelBlenderMode.cs @@ -1,14 +1,10 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; -using System.Collections.Generic; -using System.Text; - namespace SixLabors.ImageSharp.PixelFormats { /// - /// The various blending modes. + /// Enumerates the various blending modes. /// public enum PixelBlenderMode { diff --git a/src/ImageSharp/PixelFormats/Rgba32.Definitions.cs b/src/ImageSharp/PixelFormats/Rgba32.Definitions.cs index b5fed5a357..032d0b5464 100644 --- a/src/ImageSharp/PixelFormats/Rgba32.Definitions.cs +++ b/src/ImageSharp/PixelFormats/Rgba32.Definitions.cs @@ -1,12 +1,10 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; - -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.PixelFormats { /// - /// Provides standardized deifinitions for named colors. + /// Provides standardized definitions for named colors. /// public partial struct Rgba32 { diff --git a/src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs b/src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs index 89a4aba264..d87820f847 100644 --- a/src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs @@ -6,9 +6,8 @@ using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using SixLabors.ImageSharp.Memory; -using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.PixelFormats { /// /// Provides optimized overrides for bulk operations. diff --git a/src/ImageSharp/PixelFormats/Rgba32.cs b/src/ImageSharp/PixelFormats/Rgba32.cs index 83a35f1895..701de7770b 100644 --- a/src/ImageSharp/PixelFormats/Rgba32.cs +++ b/src/ImageSharp/PixelFormats/Rgba32.cs @@ -1,13 +1,11 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.PixelFormats { /// /// Packed pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255. diff --git a/src/ImageSharp/Primitives/DenseMatrix{T}.cs b/src/ImageSharp/Primitives/DenseMatrix{T}.cs new file mode 100644 index 0000000000..1f459e7cb0 --- /dev/null +++ b/src/ImageSharp/Primitives/DenseMatrix{T}.cs @@ -0,0 +1,215 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Diagnostics; +using System.Runtime.CompilerServices; + +namespace SixLabors.ImageSharp.Primitives +{ + /// + /// Represents a dense matrix with arbitrary elements. + /// Components that are adjacent in a column of the matrix are adjacent in the storage array. + /// The components are said to be stored in column major order. + /// + /// The type of elements in the matrix. + public readonly struct DenseMatrix : IEquatable> + where T : struct, IEquatable + { + /// + /// The 1D representation of the dense matrix. + /// + public readonly T[] Data; + + /// + /// Gets the number of columns in the dense matrix. + /// + public readonly int Columns; + + /// + /// Gets the number of rows in the dense matrix. + /// + public readonly int Rows; + + /// + /// Gets the number of items in the array. + /// + public readonly int Count; + + /// + /// Initializes a new instance of the struct. + /// + /// The length of each side in the matrix. + public DenseMatrix(int length) + : this(length, length) + { + } + + /// + /// Initializes a new instance of the struct. + /// + /// The number of columns. + /// The number of rows. + public DenseMatrix(int columns, int rows) + { + Guard.MustBeGreaterThan(columns, 0, nameof(columns)); + Guard.MustBeGreaterThan(rows, 0, nameof(rows)); + + this.Rows = rows; + this.Columns = columns; + this.Count = columns * rows; + this.Data = new T[this.Columns * this.Rows]; + } + + /// + /// Initializes a new instance of the struct. + /// + /// The 2D array to provide access to. + public DenseMatrix(T[,] data) + { + Guard.NotNull(data, nameof(data)); + int rows = data.GetLength(0); + int columns = data.GetLength(1); + + Guard.MustBeGreaterThan(rows, 0, nameof(this.Rows)); + Guard.MustBeGreaterThan(columns, 0, nameof(this.Columns)); + + this.Rows = rows; + this.Columns = columns; + this.Count = this.Columns * this.Rows; + this.Data = new T[this.Columns * this.Rows]; + + for (int y = 0; y < this.Rows; y++) + { + for (int x = 0; x < this.Columns; x++) + { + ref T value = ref this[y, x]; + value = data[y, x]; + } + } + } + + /// + /// Gets or sets the item at the specified position. + /// + /// The row-coordinate of the item. Must be greater than or equal to zero and less than the height of the array. + /// The column-coordinate of the item. Must be greater than or equal to zero and less than the width of the array. + /// The at the specified position. + public ref T this[int row, int column] + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + this.CheckCoordinates(row, column); + return ref this.Data[(row * this.Columns) + column]; + } + } + + /// + /// Performs an implicit conversion from a to a . + /// + /// The source array. + /// + /// The representation on the source data. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static implicit operator DenseMatrix(T[,] data) => new DenseMatrix(data); + + /// + /// Performs an implicit conversion from a to a . + /// + /// The source array. + /// + /// The representation on the source data. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#pragma warning disable SA1008 // Opening parenthesis should be spaced correctly + public static implicit operator T[,] (DenseMatrix data) +#pragma warning restore SA1008 // Opening parenthesis should be spaced correctly + { + var result = new T[data.Rows, data.Columns]; + + for (int y = 0; y < data.Rows; y++) + { + for (int x = 0; x < data.Columns; x++) + { + ref T value = ref result[y, x]; + value = data[y, x]; + } + } + + return result; + } + + /// + /// Fills the matrix with the given value + /// + /// The value to fill each item with + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Fill(T value) + { + for (int i = 0; i < this.Data.Length; i++) + { + this.Data[i] = value; + } + } + + /// + /// Clears the matrix setting each value to the default value for the element type + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Clear() => Array.Clear(this.Data, 0, this.Data.Length); + + /// + /// Checks the coordinates to ensure they are within bounds. + /// + /// The y-coordinate of the item. Must be greater than zero and smaller than the height of the matrix. + /// The x-coordinate of the item. Must be greater than zero and smaller than the width of the matrix. + /// + /// Thrown if the coordinates are not within the bounds of the array. + /// + [Conditional("DEBUG")] + private void CheckCoordinates(int row, int column) + { + if (row < 0 || row >= this.Rows) + { + throw new ArgumentOutOfRangeException(nameof(row), row, $"{row} is outwith the matrix bounds."); + } + + if (column < 0 || column >= this.Columns) + { + throw new ArgumentOutOfRangeException(nameof(column), column, $"{column} is outwith the matrix bounds."); + } + } + + /// + public bool Equals(DenseMatrix other) + { + if (this.Columns != other.Columns) + { + return false; + } + + if (this.Rows != other.Rows) + { + return false; + } + + for (int i = 0; i < this.Data.Length; i++) + { + if (!this.Data[i].Equals(other.Data[i])) + { + return false; + } + } + + return true; + } + + /// + public override bool Equals(object obj) => obj is DenseMatrix matrix && this.Equals(matrix); + + /// + public override int GetHashCode() => this.Data.GetHashCode(); + } +} \ No newline at end of file diff --git a/src/ImageSharp/Numerics/ValueSize.cs b/src/ImageSharp/Primitives/ValueSize.cs similarity index 81% rename from src/ImageSharp/Numerics/ValueSize.cs rename to src/ImageSharp/Primitives/ValueSize.cs index fcf61a586d..8af9ba2e48 100644 --- a/src/ImageSharp/Numerics/ValueSize.cs +++ b/src/ImageSharp/Primitives/ValueSize.cs @@ -4,7 +4,7 @@ using System; using SixLabors.Primitives; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Primitives { /// /// Represents a value in relation to a value on the image @@ -28,7 +28,7 @@ namespace SixLabors.ImageSharp } /// - /// The different vlaue types + /// Enumerates the different value types /// public enum ValueSizeType { @@ -38,12 +38,12 @@ namespace SixLabors.ImageSharp Absolute, /// - /// The value is a percentage of the Images Width + /// The value is a percentage of the image width /// PercentageOfWidth, /// - /// The value is a percentage of the Images height + /// The value is a percentage of the images height /// PercentageOfHeight } @@ -61,9 +61,9 @@ namespace SixLabors.ImageSharp /// /// Implicitly converts a float into an absolute value /// - /// the vlaue to use as the absolute figure. - public static implicit operator ValueSize(float d) - => Absolute(d); + /// the value to use as the absolute figure. + public static implicit operator ValueSize(float f) + => Absolute(f); /// /// Create a new ValueSize with as a PercentageOfWidth type with value set to percentage. @@ -99,7 +99,7 @@ namespace SixLabors.ImageSharp /// Calculates the specified size. /// /// The size. - /// The calucalted value + /// The calculated value public float Calculate(Size size) { switch (this.Type) @@ -120,10 +120,22 @@ namespace SixLabors.ImageSharp return $"{this.Value} - {this.Type}"; } + /// + public override bool Equals(object obj) + { + return obj is ValueSize size && this.Equals(size); + } + /// public bool Equals(ValueSize other) { - return this.Type == other.Type && this.Value == other.Value; + return this.Type == other.Type && this.Value.Equals(other.Value); + } + + /// + public override int GetHashCode() + { + return HashHelpers.Combine(this.Value.GetHashCode(), this.Type.GetHashCode()); } } } diff --git a/src/ImageSharp/Processing/Binarization/BinaryDiffuse.cs b/src/ImageSharp/Processing/Binarization/BinaryDiffuseExtensions.cs similarity index 81% rename from src/ImageSharp/Processing/Binarization/BinaryDiffuse.cs rename to src/ImageSharp/Processing/Binarization/BinaryDiffuseExtensions.cs index eb50087570..a2859b011b 100644 --- a/src/ImageSharp/Processing/Binarization/BinaryDiffuse.cs +++ b/src/ImageSharp/Processing/Binarization/BinaryDiffuseExtensions.cs @@ -1,17 +1,17 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Dithering; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Binarization.Processors; +using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion; using SixLabors.Primitives; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Binarization { /// - /// Extension methods for the type. + /// Adds binary diffusion extensions to the type. /// - public static partial class ImageExtensions + public static class BinaryDiffuseExtensions { /// /// Dithers the image reducing it to two colors using error diffusion. @@ -23,10 +23,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext BinaryDiffuse(this IImageProcessingContext source, IErrorDiffuser diffuser, float threshold) where TPixel : struct, IPixel - { - source.ApplyProcessor(new BinaryErrorDiffusionProcessor(diffuser, threshold)); - return source; - } + => source.ApplyProcessor(new BinaryErrorDiffusionProcessor(diffuser, threshold)); /// /// Dithers the image reducing it to two colors using error diffusion. @@ -41,10 +38,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext BinaryDiffuse(this IImageProcessingContext source, IErrorDiffuser diffuser, float threshold, Rectangle rectangle) where TPixel : struct, IPixel - { - source.ApplyProcessor(new BinaryErrorDiffusionProcessor(diffuser, threshold), rectangle); - return source; - } + => source.ApplyProcessor(new BinaryErrorDiffusionProcessor(diffuser, threshold), rectangle); /// /// Dithers the image reducing it to two colors using error diffusion. @@ -58,10 +52,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext BinaryDiffuse(this IImageProcessingContext source, IErrorDiffuser diffuser, float threshold, TPixel upperColor, TPixel lowerColor) where TPixel : struct, IPixel - { - source.ApplyProcessor(new BinaryErrorDiffusionProcessor(diffuser, threshold, upperColor, lowerColor)); - return source; - } + => source.ApplyProcessor(new BinaryErrorDiffusionProcessor(diffuser, threshold, upperColor, lowerColor)); /// /// Dithers the image reducing it to two colors using error diffusion. @@ -78,9 +69,6 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext BinaryDiffuse(this IImageProcessingContext source, IErrorDiffuser diffuser, float threshold, TPixel upperColor, TPixel lowerColor, Rectangle rectangle) where TPixel : struct, IPixel - { - source.ApplyProcessor(new BinaryErrorDiffusionProcessor(diffuser, threshold, upperColor, lowerColor), rectangle); - return source; - } + => source.ApplyProcessor(new BinaryErrorDiffusionProcessor(diffuser, threshold, upperColor, lowerColor), rectangle); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Binarization/BinaryDither.cs b/src/ImageSharp/Processing/Binarization/BinaryDitherExtensions.cs similarity index 80% rename from src/ImageSharp/Processing/Binarization/BinaryDither.cs rename to src/ImageSharp/Processing/Binarization/BinaryDitherExtensions.cs index 715dff472d..e66be55de2 100644 --- a/src/ImageSharp/Processing/Binarization/BinaryDither.cs +++ b/src/ImageSharp/Processing/Binarization/BinaryDitherExtensions.cs @@ -1,17 +1,17 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Dithering; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Binarization.Processors; +using SixLabors.ImageSharp.Processing.Dithering.Ordered; using SixLabors.Primitives; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Binarization { /// - /// Extension methods for the type. + /// Adds binary dithering extensions to the type. /// - public static partial class ImageExtensions + public static class BinaryDitherExtensions { /// /// Dithers the image reducing it to two colors using ordered dithering. @@ -22,10 +22,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext BinaryDither(this IImageProcessingContext source, IOrderedDither dither) where TPixel : struct, IPixel - { - source.ApplyProcessor(new BinaryOrderedDitherProcessor(dither)); - return source; - } + => source.ApplyProcessor(new BinaryOrderedDitherProcessor(dither)); /// /// Dithers the image reducing it to two colors using ordered dithering. @@ -38,10 +35,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext BinaryDither(this IImageProcessingContext source, IOrderedDither dither, TPixel upperColor, TPixel lowerColor) where TPixel : struct, IPixel - { - source.ApplyProcessor(new BinaryOrderedDitherProcessor(dither, upperColor, lowerColor)); - return source; - } + => source.ApplyProcessor(new BinaryOrderedDitherProcessor(dither, upperColor, lowerColor)); /// /// Dithers the image reducing it to two colors using ordered dithering. @@ -55,10 +49,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext BinaryDither(this IImageProcessingContext source, IOrderedDither dither, Rectangle rectangle) where TPixel : struct, IPixel - { - source.ApplyProcessor(new BinaryOrderedDitherProcessor(dither), rectangle); - return source; - } + => source.ApplyProcessor(new BinaryOrderedDitherProcessor(dither), rectangle); /// /// Dithers the image reducing it to two colors using ordered dithering. @@ -74,9 +65,6 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext BinaryDither(this IImageProcessingContext source, IOrderedDither dither, TPixel upperColor, TPixel lowerColor, Rectangle rectangle) where TPixel : struct, IPixel - { - source.ApplyProcessor(new BinaryOrderedDitherProcessor(dither, upperColor, lowerColor), rectangle); - return source; - } + => source.ApplyProcessor(new BinaryOrderedDitherProcessor(dither, upperColor, lowerColor), rectangle); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Binarization/BinaryThreshold.cs b/src/ImageSharp/Processing/Binarization/BinaryThresholdExtensions.cs similarity index 82% rename from src/ImageSharp/Processing/Binarization/BinaryThreshold.cs rename to src/ImageSharp/Processing/Binarization/BinaryThresholdExtensions.cs index 3f86528f51..0050613948 100644 --- a/src/ImageSharp/Processing/Binarization/BinaryThreshold.cs +++ b/src/ImageSharp/Processing/Binarization/BinaryThresholdExtensions.cs @@ -2,15 +2,15 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Binarization.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Binarization { /// - /// Extension methods for the type. + /// Adds binary thresholding extensions to the type. /// - public static partial class ImageExtensions + public static class BinaryThresholdExtensions { /// /// Applies binarization to the image splitting the pixels at the given threshold. @@ -21,10 +21,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext BinaryThreshold(this IImageProcessingContext source, float threshold) where TPixel : struct, IPixel - { - source.ApplyProcessor(new BinaryThresholdProcessor(threshold)); - return source; - } + => source.ApplyProcessor(new BinaryThresholdProcessor(threshold)); /// /// Applies binarization to the image splitting the pixels at the given threshold. @@ -38,10 +35,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext BinaryThreshold(this IImageProcessingContext source, float threshold, Rectangle rectangle) where TPixel : struct, IPixel - { - source.ApplyProcessor(new BinaryThresholdProcessor(threshold), rectangle); - return source; - } + => source.ApplyProcessor(new BinaryThresholdProcessor(threshold), rectangle); /// /// Applies binarization to the image splitting the pixels at the given threshold. @@ -54,10 +48,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext BinaryThreshold(this IImageProcessingContext source, float threshold, TPixel upperColor, TPixel lowerColor) where TPixel : struct, IPixel - { - source.ApplyProcessor(new BinaryThresholdProcessor(threshold, upperColor, lowerColor)); - return source; - } + => source.ApplyProcessor(new BinaryThresholdProcessor(threshold, upperColor, lowerColor)); /// /// Applies binarization to the image splitting the pixels at the given threshold. @@ -73,9 +64,6 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext BinaryThreshold(this IImageProcessingContext source, float threshold, TPixel upperColor, TPixel lowerColor, Rectangle rectangle) where TPixel : struct, IPixel - { - source.ApplyProcessor(new BinaryThresholdProcessor(threshold, upperColor, lowerColor), rectangle); - return source; - } + => source.ApplyProcessor(new BinaryThresholdProcessor(threshold, upperColor, lowerColor), rectangle); } } diff --git a/src/ImageSharp/Processing/Processors/Binarization/BinaryErrorDiffusionProcessor.cs b/src/ImageSharp/Processing/Binarization/Processors/BinaryErrorDiffusionProcessor.cs similarity index 94% rename from src/ImageSharp/Processing/Processors/Binarization/BinaryErrorDiffusionProcessor.cs rename to src/ImageSharp/Processing/Binarization/Processors/BinaryErrorDiffusionProcessor.cs index 80a4236452..6588bbe5b3 100644 --- a/src/ImageSharp/Processing/Processors/Binarization/BinaryErrorDiffusionProcessor.cs +++ b/src/ImageSharp/Processing/Binarization/Processors/BinaryErrorDiffusionProcessor.cs @@ -3,12 +3,12 @@ using System; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Dithering; -using SixLabors.ImageSharp.Helpers; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion; +using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Binarization.Processors { /// /// Performs binary threshold filtering against an image using error diffusion. @@ -75,7 +75,7 @@ namespace SixLabors.ImageSharp.Processing.Processors public TPixel LowerColor { get; } /// - protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) + protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { float threshold = this.Threshold * 255F; var rgba = default(Rgba32); diff --git a/src/ImageSharp/Processing/Processors/Binarization/BinaryOrderedDitherProcessor.cs b/src/ImageSharp/Processing/Binarization/Processors/BinaryOrderedDitherProcessor.cs similarity index 92% rename from src/ImageSharp/Processing/Processors/Binarization/BinaryOrderedDitherProcessor.cs rename to src/ImageSharp/Processing/Binarization/Processors/BinaryOrderedDitherProcessor.cs index baa8df8cca..bd4b3660a1 100644 --- a/src/ImageSharp/Processing/Processors/Binarization/BinaryOrderedDitherProcessor.cs +++ b/src/ImageSharp/Processing/Binarization/Processors/BinaryOrderedDitherProcessor.cs @@ -3,12 +3,12 @@ using System; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Dithering; -using SixLabors.ImageSharp.Helpers; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Dithering.Ordered; +using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Binarization.Processors { /// /// Performs binary threshold filtering against an image using ordered dithering. @@ -57,7 +57,7 @@ namespace SixLabors.ImageSharp.Processing.Processors public TPixel LowerColor { get; } /// - protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) + protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { var rgba = default(Rgba32); bool isAlphaOnly = typeof(TPixel) == typeof(Alpha8); diff --git a/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs b/src/ImageSharp/Processing/Binarization/Processors/BinaryThresholdProcessor.cs similarity index 93% rename from src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs rename to src/ImageSharp/Processing/Binarization/Processors/BinaryThresholdProcessor.cs index 609b090923..455c6ad8cd 100644 --- a/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs +++ b/src/ImageSharp/Processing/Binarization/Processors/BinaryThresholdProcessor.cs @@ -4,11 +4,11 @@ using System; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Helpers; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Binarization.Processors { /// /// Performs simple binary threshold filtering against an image. @@ -56,7 +56,7 @@ namespace SixLabors.ImageSharp.Processing.Processors public TPixel LowerColor { get; set; } /// - protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) + protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { float threshold = this.Threshold * 255F; TPixel upper = this.UpperColor; diff --git a/src/ImageSharp/Processing/ColorMatrix/Lomograph.cs b/src/ImageSharp/Processing/ColorMatrix/Lomograph.cs deleted file mode 100644 index ca79841c76..0000000000 --- a/src/ImageSharp/Processing/ColorMatrix/Lomograph.cs +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; -using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Processors; -using SixLabors.Primitives; - -namespace SixLabors.ImageSharp -{ - /// - /// Extension methods for the type. - /// - public static partial class ImageExtensions - { - /// - /// Alters the colors of the image recreating an old Lomograph camera effect. - /// - /// The pixel format. - /// The image this method extends. - /// The . - public static IImageProcessingContext Lomograph(this IImageProcessingContext source) - where TPixel : struct, IPixel - { - return Lomograph(source, GraphicsOptions.Default); - } - - /// - /// Alters the colors of the image recreating an old Lomograph camera effect. - /// - /// The pixel format. - /// The image this method extends. - /// - /// The structure that specifies the portion of the image object to alter. - /// - /// The . - public static IImageProcessingContext Lomograph(this IImageProcessingContext source, Rectangle rectangle) - where TPixel : struct, IPixel - { - return Lomograph(source, rectangle, GraphicsOptions.Default); - } - - /// - /// Alters the colors of the image recreating an old Lomograph camera effect. - /// - /// The pixel format. - /// The image this method extends. - /// The options effecting pixel blending. - /// The . - public static IImageProcessingContext Lomograph(this IImageProcessingContext source, GraphicsOptions options) - where TPixel : struct, IPixel - { - source.ApplyProcessor(new LomographProcessor(source.MemoryManager, options)); - return source; - } - - /// - /// Alters the colors of the image recreating an old Lomograph camera effect. - /// - /// The pixel format. - /// The image this method extends. - /// - /// The structure that specifies the portion of the image object to alter. - /// - /// The options effecting pixel blending. - /// The . - public static IImageProcessingContext Lomograph(this IImageProcessingContext source, Rectangle rectangle, GraphicsOptions options) - where TPixel : struct, IPixel - { - source.ApplyProcessor(new LomographProcessor(source.MemoryManager, options), rectangle); - return source; - } - } -} diff --git a/src/ImageSharp/Processing/ColorMatrix/Polaroid.cs b/src/ImageSharp/Processing/ColorMatrix/Polaroid.cs deleted file mode 100644 index d12cc76122..0000000000 --- a/src/ImageSharp/Processing/ColorMatrix/Polaroid.cs +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; -using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Processors; -using SixLabors.Primitives; - -namespace SixLabors.ImageSharp -{ - /// - /// Extension methods for the type. - /// - public static partial class ImageExtensions - { - /// - /// Alters the colors of the image recreating an old Polaroid camera effect. - /// - /// The pixel format. - /// The image this method extends. - /// The . - public static IImageProcessingContext Polaroid(this IImageProcessingContext source) - where TPixel : struct, IPixel - { - return Polaroid(source, GraphicsOptions.Default); - } - - /// - /// Alters the colors of the image recreating an old Polaroid camera effect. - /// - /// The pixel format. - /// The image this method extends. - /// - /// The structure that specifies the portion of the image object to alter. - /// - /// The . - public static IImageProcessingContext Polaroid(this IImageProcessingContext source, Rectangle rectangle) - where TPixel : struct, IPixel - { - return Polaroid(source, rectangle, GraphicsOptions.Default); - } - - /// - /// Alters the colors of the image recreating an old Polaroid camera effect. - /// - /// The pixel format. - /// The image this method extends. - /// The options effecting pixel blending. - /// The . - public static IImageProcessingContext Polaroid(this IImageProcessingContext source, GraphicsOptions options) - where TPixel : struct, IPixel - { - source.ApplyProcessor(new PolaroidProcessor(source.MemoryManager, options)); - return source; - } - - /// - /// Alters the colors of the image recreating an old Polaroid camera effect. - /// - /// The pixel format. - /// The image this method extends. - /// - /// The structure that specifies the portion of the image object to alter. - /// - /// The options effecting pixel blending. - /// The . - public static IImageProcessingContext Polaroid(this IImageProcessingContext source, Rectangle rectangle, GraphicsOptions options) - where TPixel : struct, IPixel - { - source.ApplyProcessor(new PolaroidProcessor(source.MemoryManager, options), rectangle); - return source; - } - } -} diff --git a/src/ImageSharp/Processing/Convolution/BoxBlur.cs b/src/ImageSharp/Processing/Convolution/BoxBlurExtensions.cs similarity index 90% rename from src/ImageSharp/Processing/Convolution/BoxBlur.cs rename to src/ImageSharp/Processing/Convolution/BoxBlurExtensions.cs index b0c6ffc8d2..edb798fb41 100644 --- a/src/ImageSharp/Processing/Convolution/BoxBlur.cs +++ b/src/ImageSharp/Processing/Convolution/BoxBlurExtensions.cs @@ -1,17 +1,16 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Convolution.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Convolution { /// - /// Extension methods for the type. + /// Adds box blurring extensions to the type. /// - public static partial class ImageExtensions + public static class BoxBlurExtensions { /// /// Applies a box blur to the image. @@ -21,7 +20,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext BoxBlur(this IImageProcessingContext source) where TPixel : struct, IPixel - => source.ApplyProcessor(new BoxBlurProcessor(7)); + => source.ApplyProcessor(new BoxBlurProcessor()); /// /// Applies a box blur to the image. @@ -48,4 +47,4 @@ namespace SixLabors.ImageSharp where TPixel : struct, IPixel => source.ApplyProcessor(new BoxBlurProcessor(radius), rectangle); } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Convolution/DetectEdges.cs b/src/ImageSharp/Processing/Convolution/DetectEdgesExtensions.cs similarity index 74% rename from src/ImageSharp/Processing/Convolution/DetectEdges.cs rename to src/ImageSharp/Processing/Convolution/DetectEdgesExtensions.cs index 79e7ac6cf4..a2b2b244bd 100644 --- a/src/ImageSharp/Processing/Convolution/DetectEdges.cs +++ b/src/ImageSharp/Processing/Convolution/DetectEdgesExtensions.cs @@ -1,35 +1,31 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Convolution.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Convolution { /// - /// Extension methods for the type. + /// Adds edge detection extensions to the type. /// - public static partial class ImageExtensions + public static class DetectEdgesExtensions { /// /// Detects any edges within the image. Uses the filter - /// operating in Grayscale mode. + /// operating in grayscale mode. /// /// The pixel format. /// The image this method extends. /// The . public static IImageProcessingContext DetectEdges(this IImageProcessingContext source) where TPixel : struct, IPixel - { - return DetectEdges(source, new SobelProcessor { Grayscale = true }); - } + => DetectEdges(source, new SobelProcessor(true)); /// /// Detects any edges within the image. Uses the filter - /// operating in Grayscale mode. + /// operating in grayscale mode. /// /// The pixel format. /// The image this method extends. @@ -39,9 +35,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext DetectEdges(this IImageProcessingContext source, Rectangle rectangle) where TPixel : struct, IPixel - { - return DetectEdges(source, rectangle, new SobelProcessor { Grayscale = true }); - } + => DetectEdges(source, rectangle, new SobelProcessor(true)); /// /// Detects any edges within the image. @@ -50,7 +44,7 @@ namespace SixLabors.ImageSharp /// The image this method extends. /// The filter for detecting edges. /// The . - public static IImageProcessingContext DetectEdges(this IImageProcessingContext source, EdgeDetection filter) + public static IImageProcessingContext DetectEdges(this IImageProcessingContext source, EdgeDetectionOperators filter) where TPixel : struct, IPixel => DetectEdges(source, GetProcessor(filter, true)); @@ -60,9 +54,9 @@ namespace SixLabors.ImageSharp /// The pixel format. /// The image this method extends. /// The filter for detecting edges. - /// Whether to convert the image to Grayscale first. Defaults to true. + /// Whether to convert the image to grayscale first. Defaults to true. /// The . - public static IImageProcessingContext DetectEdges(this IImageProcessingContext source, EdgeDetection filter, bool grayscale) + public static IImageProcessingContext DetectEdges(this IImageProcessingContext source, EdgeDetectionOperators filter, bool grayscale) where TPixel : struct, IPixel => DetectEdges(source, GetProcessor(filter, grayscale)); @@ -75,9 +69,9 @@ namespace SixLabors.ImageSharp /// /// The structure that specifies the portion of the image object to alter. /// - /// Whether to convert the image to Grayscale first. Defaults to true. + /// Whether to convert the image to grayscale first. Defaults to true. /// The . - public static IImageProcessingContext DetectEdges(this IImageProcessingContext source, EdgeDetection filter, Rectangle rectangle, bool grayscale = true) + public static IImageProcessingContext DetectEdges(this IImageProcessingContext source, EdgeDetectionOperators filter, Rectangle rectangle, bool grayscale = true) where TPixel : struct, IPixel => DetectEdges(source, rectangle, GetProcessor(filter, grayscale)); @@ -111,51 +105,51 @@ namespace SixLabors.ImageSharp return source; } - private static IEdgeDetectorProcessor GetProcessor(EdgeDetection filter, bool grayscale) + private static IEdgeDetectorProcessor GetProcessor(EdgeDetectionOperators filter, bool grayscale) where TPixel : struct, IPixel { IEdgeDetectorProcessor processor; switch (filter) { - case EdgeDetection.Kayyali: - processor = new KayyaliProcessor { Grayscale = grayscale }; + case EdgeDetectionOperators.Kayyali: + processor = new KayyaliProcessor(grayscale); break; - case EdgeDetection.Kirsch: - processor = new KirschProcessor { Grayscale = grayscale }; + case EdgeDetectionOperators.Kirsch: + processor = new KirschProcessor(grayscale); break; - case EdgeDetection.Lapacian3X3: - processor = new Laplacian3X3Processor { Grayscale = grayscale }; + case EdgeDetectionOperators.Laplacian3x3: + processor = new Laplacian3x3Processor(grayscale); break; - case EdgeDetection.Lapacian5X5: - processor = new Laplacian5X5Processor { Grayscale = grayscale }; + case EdgeDetectionOperators.Laplacian5x5: + processor = new Laplacian5x5Processor(grayscale); break; - case EdgeDetection.LaplacianOfGaussian: - processor = new LaplacianOfGaussianProcessor { Grayscale = grayscale }; + case EdgeDetectionOperators.LaplacianOfGaussian: + processor = new LaplacianOfGaussianProcessor(grayscale); break; - case EdgeDetection.Prewitt: - processor = new PrewittProcessor { Grayscale = grayscale }; + case EdgeDetectionOperators.Prewitt: + processor = new PrewittProcessor(grayscale); break; - case EdgeDetection.RobertsCross: - processor = new RobertsCrossProcessor { Grayscale = grayscale }; + case EdgeDetectionOperators.RobertsCross: + processor = new RobertsCrossProcessor(grayscale); break; - case EdgeDetection.Robinson: - processor = new RobinsonProcessor { Grayscale = grayscale }; + case EdgeDetectionOperators.Robinson: + processor = new RobinsonProcessor(grayscale); break; - case EdgeDetection.Scharr: - processor = new ScharrProcessor { Grayscale = grayscale }; + case EdgeDetectionOperators.Scharr: + processor = new ScharrProcessor(grayscale); break; default: - processor = new SobelProcessor { Grayscale = grayscale }; + processor = new SobelProcessor(grayscale); break; } diff --git a/src/ImageSharp/Processing/Convolution/Options/EdgeDetection.cs b/src/ImageSharp/Processing/Convolution/EdgeDetectionOperators.cs similarity index 83% rename from src/ImageSharp/Processing/Convolution/Options/EdgeDetection.cs rename to src/ImageSharp/Processing/Convolution/EdgeDetectionOperators.cs index b01bb945cf..55cbbeaf7d 100644 --- a/src/ImageSharp/Processing/Convolution/Options/EdgeDetection.cs +++ b/src/ImageSharp/Processing/Convolution/EdgeDetectionOperators.cs @@ -1,12 +1,12 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing.Convolution { /// /// Enumerates the various types of defined edge detection filters. /// - public enum EdgeDetection + public enum EdgeDetectionOperators { /// /// The Kayyali operator filter. @@ -19,14 +19,14 @@ namespace SixLabors.ImageSharp.Processing Kirsch, /// - /// The Lapacian3X3 operator filter. + /// The Laplacian3X3 operator filter. /// - Lapacian3X3, + Laplacian3x3, /// - /// The Lapacian5X5 operator filter. + /// The Laplacian5X5 operator filter. /// - Lapacian5X5, + Laplacian5x5, /// /// The LaplacianOfGaussian operator filter. @@ -58,4 +58,4 @@ namespace SixLabors.ImageSharp.Processing /// Sobel } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Convolution/GaussianBlur.cs b/src/ImageSharp/Processing/Convolution/GaussianBlurExtensions.cs similarity index 89% rename from src/ImageSharp/Processing/Convolution/GaussianBlur.cs rename to src/ImageSharp/Processing/Convolution/GaussianBlurExtensions.cs index 9bca97242c..ae3eace640 100644 --- a/src/ImageSharp/Processing/Convolution/GaussianBlur.cs +++ b/src/ImageSharp/Processing/Convolution/GaussianBlurExtensions.cs @@ -1,18 +1,16 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Convolution.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Convolution { /// - /// Extension methods for the type. + /// Adds Gaussian blurring extensions to the type. /// - public static partial class ImageExtensions + public static class GaussianBlurExtensions { /// /// Applies a Gaussian blur to the image. @@ -22,7 +20,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext GaussianBlur(this IImageProcessingContext source) where TPixel : struct, IPixel - => source.ApplyProcessor(new GaussianBlurProcessor(3f)); + => source.ApplyProcessor(new GaussianBlurProcessor()); /// /// Applies a Gaussian blur to the image. diff --git a/src/ImageSharp/Processing/Convolution/GaussianSharpen.cs b/src/ImageSharp/Processing/Convolution/GaussianSharpenExtensions.cs similarity index 89% rename from src/ImageSharp/Processing/Convolution/GaussianSharpen.cs rename to src/ImageSharp/Processing/Convolution/GaussianSharpenExtensions.cs index 1cea2dae9b..334a02b79b 100644 --- a/src/ImageSharp/Processing/Convolution/GaussianSharpen.cs +++ b/src/ImageSharp/Processing/Convolution/GaussianSharpenExtensions.cs @@ -1,18 +1,16 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Convolution.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Convolution { /// - /// Extension methods for the type. + /// Adds Gaussian sharpening extensions to the type. /// - public static partial class ImageExtensions + public static class GaussianSharpenExtensions { /// /// Applies a Gaussian sharpening filter to the image. @@ -22,7 +20,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext GaussianSharpen(this IImageProcessingContext source) where TPixel : struct, IPixel - => source.ApplyProcessor(new GaussianSharpenProcessor(3f)); + => source.ApplyProcessor(new GaussianSharpenProcessor()); /// /// Applies a Gaussian sharpening filter to the image. diff --git a/src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs b/src/ImageSharp/Processing/Convolution/Processors/BoxBlurProcessor.cs similarity index 78% rename from src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs rename to src/ImageSharp/Processing/Convolution/Processors/BoxBlurProcessor.cs index 8056141a09..886fb5d75e 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs +++ b/src/ImageSharp/Processing/Convolution/Processors/BoxBlurProcessor.cs @@ -1,15 +1,15 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Primitives; +using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Convolution.Processors { /// - /// Applies a Box blur sampler to the image. + /// Applies box blur processing to the image. /// /// The pixel format. internal class BoxBlurProcessor : ImageProcessor @@ -42,15 +42,15 @@ namespace SixLabors.ImageSharp.Processing.Processors /// /// Gets the horizontal gradient operator. /// - public Fast2DArray KernelX { get; } + public DenseMatrix KernelX { get; } /// /// Gets the vertical gradient operator. /// - public Fast2DArray KernelY { get; } + public DenseMatrix KernelY { get; } /// - protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) + protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { new Convolution2PassProcessor(this.KernelX, this.KernelY).Apply(source, sourceRectangle, configuration); } @@ -59,13 +59,13 @@ namespace SixLabors.ImageSharp.Processing.Processors /// Create a 1 dimensional Box kernel. /// /// Whether to calculate a horizontal kernel. - /// The - private Fast2DArray CreateBoxKernel(bool horizontal) + /// The + private DenseMatrix CreateBoxKernel(bool horizontal) { int size = this.kernelSize; - Fast2DArray kernel = horizontal - ? new Fast2DArray(size, 1) - : new Fast2DArray(1, size); + DenseMatrix kernel = horizontal + ? new DenseMatrix(size, 1) + : new DenseMatrix(1, size); float sum = 0F; for (int i = 0; i < size; i++) diff --git a/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor.cs b/src/ImageSharp/Processing/Convolution/Processors/Convolution2DProcessor.cs similarity index 85% rename from src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor.cs rename to src/ImageSharp/Processing/Convolution/Processors/Convolution2DProcessor.cs index 2c13ead162..ebadd28507 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor.cs +++ b/src/ImageSharp/Processing/Convolution/Processors/Convolution2DProcessor.cs @@ -7,12 +7,14 @@ using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Primitives; +using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Convolution.Processors { /// - /// Defines a sampler that uses two one-dimensional matrices to perform convolution against an image. + /// Defines a processor that uses two one-dimensional matrices to perform convolution against an image. /// /// The pixel format. internal class Convolution2DProcessor : ImageProcessor @@ -23,7 +25,7 @@ namespace SixLabors.ImageSharp.Processing.Processors /// /// The horizontal gradient operator. /// The vertical gradient operator. - public Convolution2DProcessor(Fast2DArray kernelX, Fast2DArray kernelY) + public Convolution2DProcessor(DenseMatrix kernelX, DenseMatrix kernelY) { this.KernelX = kernelX; this.KernelY = kernelY; @@ -32,20 +34,20 @@ namespace SixLabors.ImageSharp.Processing.Processors /// /// Gets the horizontal gradient operator. /// - public Fast2DArray KernelX { get; } + public DenseMatrix KernelX { get; } /// /// Gets the vertical gradient operator. /// - public Fast2DArray KernelY { get; } + public DenseMatrix KernelY { get; } /// - protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) + protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { - int kernelYHeight = this.KernelY.Height; - int kernelYWidth = this.KernelY.Width; - int kernelXHeight = this.KernelX.Height; - int kernelXWidth = this.KernelX.Width; + int kernelYHeight = this.KernelY.Rows; + int kernelYWidth = this.KernelY.Columns; + int kernelXHeight = this.KernelX.Rows; + int kernelXWidth = this.KernelX.Columns; int radiusY = kernelYHeight >> 1; int radiusX = kernelXWidth >> 1; diff --git a/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor.cs b/src/ImageSharp/Processing/Convolution/Processors/Convolution2PassProcessor.cs similarity index 84% rename from src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor.cs rename to src/ImageSharp/Processing/Convolution/Processors/Convolution2PassProcessor.cs index 0d87aa1dc4..8f96546aeb 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor.cs +++ b/src/ImageSharp/Processing/Convolution/Processors/Convolution2PassProcessor.cs @@ -4,16 +4,16 @@ using System; using System.Numerics; using System.Threading.Tasks; -using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Helpers; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Primitives; +using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Convolution.Processors { /// - /// Defines a sampler that uses two one-dimensional matrices to perform two-pass convolution against an image. + /// Defines a processor that uses two one-dimensional matrices to perform two-pass convolution against an image. /// /// The pixel format. internal class Convolution2PassProcessor : ImageProcessor @@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.Processing.Processors /// /// The horizontal gradient operator. /// The vertical gradient operator. - public Convolution2PassProcessor(Fast2DArray kernelX, Fast2DArray kernelY) + public Convolution2PassProcessor(DenseMatrix kernelX, DenseMatrix kernelY) { this.KernelX = kernelX; this.KernelY = kernelY; @@ -33,15 +33,15 @@ namespace SixLabors.ImageSharp.Processing.Processors /// /// Gets the horizontal gradient operator. /// - public Fast2DArray KernelX { get; } + public DenseMatrix KernelX { get; } /// /// Gets the vertical gradient operator. /// - public Fast2DArray KernelY { get; } + public DenseMatrix KernelY { get; } /// - protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) + protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { ParallelOptions parallelOptions = configuration.ParallelOptions; @@ -62,16 +62,16 @@ namespace SixLabors.ImageSharp.Processing.Processors /// The structure that specifies the portion of the image object to draw. /// /// The kernel operator. - /// The parellel options + /// The parallel options private void ApplyConvolution( Buffer2D targetPixels, Buffer2D sourcePixels, Rectangle sourceRectangle, - Fast2DArray kernel, + DenseMatrix kernel, ParallelOptions parallelOptions) { - int kernelHeight = kernel.Height; - int kernelWidth = kernel.Width; + int kernelHeight = kernel.Rows; + int kernelWidth = kernel.Columns; int radiusY = kernelHeight >> 1; int radiusX = kernelWidth >> 1; diff --git a/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor.cs b/src/ImageSharp/Processing/Convolution/Processors/ConvolutionProcessor.cs similarity index 86% rename from src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor.cs rename to src/ImageSharp/Processing/Convolution/Processors/ConvolutionProcessor.cs index 2f369113d9..8f7a1caab7 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor.cs +++ b/src/ImageSharp/Processing/Convolution/Processors/ConvolutionProcessor.cs @@ -5,15 +5,16 @@ using System; using System.Numerics; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Helpers; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Primitives; +using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Convolution.Processors { /// - /// Defines a sampler that uses a 2 dimensional matrix to perform convolution against an image. + /// Defines a processor that uses a 2 dimensional matrix to perform convolution against an image. /// /// The pixel format. internal class ConvolutionProcessor : ImageProcessor @@ -23,7 +24,7 @@ namespace SixLabors.ImageSharp.Processing.Processors /// Initializes a new instance of the class. /// /// The 2d gradient operator. - public ConvolutionProcessor(Fast2DArray kernelXY) + public ConvolutionProcessor(DenseMatrix kernelXY) { this.KernelXY = kernelXY; } @@ -31,12 +32,12 @@ namespace SixLabors.ImageSharp.Processing.Processors /// /// Gets the 2d gradient operator. /// - public Fast2DArray KernelXY { get; } + public DenseMatrix KernelXY { get; } /// - protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) + protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { - int kernelLength = this.KernelXY.Height; + int kernelLength = this.KernelXY.Rows; int radius = kernelLength >> 1; int startY = sourceRectangle.Y; diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetector2DProcessor.cs b/src/ImageSharp/Processing/Convolution/Processors/EdgeDetector2DProcessor.cs similarity index 60% rename from src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetector2DProcessor.cs rename to src/ImageSharp/Processing/Convolution/Processors/EdgeDetector2DProcessor.cs index 741a6e308c..c3530647ac 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetector2DProcessor.cs +++ b/src/ImageSharp/Processing/Convolution/Processors/EdgeDetector2DProcessor.cs @@ -1,15 +1,16 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Primitives; +using SixLabors.ImageSharp.Processing.Filters.Processors; +using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Convolution.Processors { /// - /// Defines a sampler that detects edges within an image using two one-dimensional matrices. + /// Defines a processor that detects edges within an image using two one-dimensional matrices. /// /// The pixel format. internal abstract class EdgeDetector2DProcessor : ImageProcessor, IEdgeDetectorProcessor @@ -20,33 +21,35 @@ namespace SixLabors.ImageSharp.Processing.Processors /// /// The horizontal gradient operator. /// The vertical gradient operator. - protected EdgeDetector2DProcessor(Fast2DArray kernelX, Fast2DArray kernelY) + /// Whether to convert the image to grayscale before performing edge detection. + protected EdgeDetector2DProcessor(DenseMatrix kernelX, DenseMatrix kernelY, bool grayscale) { this.KernelX = kernelX; this.KernelY = kernelY; + this.Grayscale = grayscale; } /// /// Gets the horizontal gradient operator. /// - public Fast2DArray KernelX { get; } + public DenseMatrix KernelX { get; } /// /// Gets the vertical gradient operator. /// - public Fast2DArray KernelY { get; } + public DenseMatrix KernelY { get; } /// public bool Grayscale { get; set; } /// - protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) + protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { new Convolution2DProcessor(this.KernelX, this.KernelY).Apply(source, sourceRectangle, configuration); } /// - protected override void BeforeApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) + protected override void BeforeFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { if (this.Grayscale) { diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs b/src/ImageSharp/Processing/Convolution/Processors/EdgeDetectorCompassProcessor.cs similarity index 73% rename from src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs rename to src/ImageSharp/Processing/Convolution/Processors/EdgeDetectorCompassProcessor.cs index 0ffd7d48f5..bcedd7a3cd 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs +++ b/src/ImageSharp/Processing/Convolution/Processors/EdgeDetectorCompassProcessor.cs @@ -4,65 +4,75 @@ using System; using System.Numerics; using System.Threading.Tasks; -using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Primitives; +using SixLabors.ImageSharp.Processing.Filters.Processors; +using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Convolution.Processors { /// - /// Defines a sampler that detects edges within an image using a eight two dimensional matrices. + /// Defines a processor that detects edges within an image using a eight two dimensional matrices. /// /// The pixel format. internal abstract class EdgeDetectorCompassProcessor : ImageProcessor, IEdgeDetectorProcessor where TPixel : struct, IPixel { + /// + /// Initializes a new instance of the class. + /// + /// Whether to convert the image to grayscale before performing edge detection. + protected EdgeDetectorCompassProcessor(bool grayscale) + { + this.Grayscale = grayscale; + } + /// /// Gets the North gradient operator /// - public abstract Fast2DArray North { get; } + public abstract DenseMatrix North { get; } /// /// Gets the NorthWest gradient operator /// - public abstract Fast2DArray NorthWest { get; } + public abstract DenseMatrix NorthWest { get; } /// /// Gets the West gradient operator /// - public abstract Fast2DArray West { get; } + public abstract DenseMatrix West { get; } /// /// Gets the SouthWest gradient operator /// - public abstract Fast2DArray SouthWest { get; } + public abstract DenseMatrix SouthWest { get; } /// /// Gets the South gradient operator /// - public abstract Fast2DArray South { get; } + public abstract DenseMatrix South { get; } /// /// Gets the SouthEast gradient operator /// - public abstract Fast2DArray SouthEast { get; } + public abstract DenseMatrix SouthEast { get; } /// /// Gets the East gradient operator /// - public abstract Fast2DArray East { get; } + public abstract DenseMatrix East { get; } /// /// Gets the NorthEast gradient operator /// - public abstract Fast2DArray NorthEast { get; } + public abstract DenseMatrix NorthEast { get; } /// - public bool Grayscale { get; set; } + public bool Grayscale { get; } /// - protected override void BeforeApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) + protected override void BeforeFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { if (this.Grayscale) { @@ -71,9 +81,9 @@ namespace SixLabors.ImageSharp.Processing.Processors } /// - protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) + protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { - Fast2DArray[] kernels = { this.North, this.NorthWest, this.West, this.SouthWest, this.South, this.SouthEast, this.East, this.NorthEast }; + DenseMatrix[] kernels = { this.North, this.NorthWest, this.West, this.SouthWest, this.South, this.SouthEast, this.East, this.NorthEast }; int startY = sourceRectangle.Y; int endY = sourceRectangle.Bottom; diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorProcessor.cs b/src/ImageSharp/Processing/Convolution/Processors/EdgeDetectorProcessor.cs similarity index 56% rename from src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorProcessor.cs rename to src/ImageSharp/Processing/Convolution/Processors/EdgeDetectorProcessor.cs index e5c5179716..e0ca838288 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorProcessor.cs +++ b/src/ImageSharp/Processing/Convolution/Processors/EdgeDetectorProcessor.cs @@ -1,15 +1,16 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Primitives; +using SixLabors.ImageSharp.Processing.Filters.Processors; +using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Convolution.Processors { /// - /// Defines a sampler that detects edges within an image using a single two dimensional matrix. + /// Defines a processor that detects edges within an image using a single two dimensional matrix. /// /// The pixel format. internal abstract class EdgeDetectorProcessor : ImageProcessor, IEdgeDetectorProcessor @@ -19,21 +20,23 @@ namespace SixLabors.ImageSharp.Processing.Processors /// Initializes a new instance of the class. /// /// The 2d gradient operator. - protected EdgeDetectorProcessor(Fast2DArray kernelXY) + /// Whether to convert the image to grayscale before performing edge detection. + protected EdgeDetectorProcessor(DenseMatrix kernelXY, bool grayscale) { this.KernelXY = kernelXY; + this.Grayscale = grayscale; } /// - public bool Grayscale { get; set; } + public bool Grayscale { get; } /// /// Gets the 2d gradient operator. /// - public Fast2DArray KernelXY { get; } + public DenseMatrix KernelXY { get; } /// - protected override void BeforeApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) + protected override void BeforeFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { if (this.Grayscale) { @@ -42,7 +45,7 @@ namespace SixLabors.ImageSharp.Processing.Processors } /// - protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) + protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { new ConvolutionProcessor(this.KernelXY).Apply(source, sourceRectangle, configuration); } diff --git a/src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs b/src/ImageSharp/Processing/Convolution/Processors/GaussianBlurProcessor.cs similarity index 79% rename from src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs rename to src/ImageSharp/Processing/Convolution/Processors/GaussianBlurProcessor.cs index c897efeed8..6f33e23ec1 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs +++ b/src/ImageSharp/Processing/Convolution/Processors/GaussianBlurProcessor.cs @@ -2,14 +2,15 @@ // Licensed under the Apache License, Version 2.0. using System; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Primitives; +using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Convolution.Processors { /// - /// Applies a Gaussian blur sampler to the image. + /// Applies Gaussian blur processing to the image. /// /// The pixel format. internal class GaussianBlurProcessor : ImageProcessor @@ -20,19 +21,14 @@ namespace SixLabors.ImageSharp.Processing.Processors /// private readonly int kernelSize; - /// - /// The spread of the blur. - /// - private readonly float sigma; - /// /// Initializes a new instance of the class. /// /// The 'sigma' value representing the weight of the blur. - public GaussianBlurProcessor(float sigma = 3f) + public GaussianBlurProcessor(float sigma = 3F) { this.kernelSize = ((int)Math.Ceiling(sigma) * 2) + 1; - this.sigma = sigma; + this.Sigma = sigma; this.KernelX = this.CreateGaussianKernel(true); this.KernelY = this.CreateGaussianKernel(false); } @@ -46,7 +42,7 @@ namespace SixLabors.ImageSharp.Processing.Processors public GaussianBlurProcessor(int radius) { this.kernelSize = (radius * 2) + 1; - this.sigma = radius; + this.Sigma = radius; this.KernelX = this.CreateGaussianKernel(true); this.KernelY = this.CreateGaussianKernel(false); } @@ -64,28 +60,28 @@ namespace SixLabors.ImageSharp.Processing.Processors public GaussianBlurProcessor(float sigma, int radius) { this.kernelSize = (radius * 2) + 1; - this.sigma = sigma; + this.Sigma = sigma; this.KernelX = this.CreateGaussianKernel(true); this.KernelY = this.CreateGaussianKernel(false); } /// - /// Gets the sigma + /// Gets the sigma value representing the weight of the blur /// - public float Sigma => this.sigma; + public float Sigma { get; } /// /// Gets the horizontal gradient operator. /// - public Fast2DArray KernelX { get; } + public DenseMatrix KernelX { get; } /// /// Gets the vertical gradient operator. /// - public Fast2DArray KernelY { get; } + public DenseMatrix KernelY { get; } /// - protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) + protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { new Convolution2PassProcessor(this.KernelX, this.KernelY).Apply(source, sourceRectangle, configuration); } @@ -94,14 +90,14 @@ namespace SixLabors.ImageSharp.Processing.Processors /// Create a 1 dimensional Gaussian kernel using the Gaussian G(x) function /// /// Whether to calculate a horizontal kernel. - /// The - private Fast2DArray CreateGaussianKernel(bool horizontal) + /// The + private DenseMatrix CreateGaussianKernel(bool horizontal) { int size = this.kernelSize; - float weight = this.sigma; - Fast2DArray kernel = horizontal - ? new Fast2DArray(size, 1) - : new Fast2DArray(1, size); + float weight = this.Sigma; + DenseMatrix kernel = horizontal + ? new DenseMatrix(size, 1) + : new DenseMatrix(1, size); float sum = 0F; float midpoint = (size - 1) / 2F; diff --git a/src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs b/src/ImageSharp/Processing/Convolution/Processors/GaussianSharpenProcessor.cs similarity index 81% rename from src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs rename to src/ImageSharp/Processing/Convolution/Processors/GaussianSharpenProcessor.cs index b960e9075f..5f296e29ee 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs +++ b/src/ImageSharp/Processing/Convolution/Processors/GaussianSharpenProcessor.cs @@ -2,14 +2,15 @@ // Licensed under the Apache License, Version 2.0. using System; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Primitives; +using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Convolution.Processors { /// - /// Applies a Gaussian sharpening sampler to the image. + /// Applies Gaussian sharpening processing to the image. /// /// The pixel format. internal class GaussianSharpenProcessor : ImageProcessor @@ -20,21 +21,16 @@ namespace SixLabors.ImageSharp.Processing.Processors /// private readonly int kernelSize; - /// - /// The spread of the blur. - /// - private readonly float sigma; - /// /// Initializes a new instance of the class. /// /// /// The 'sigma' value representing the weight of the sharpening. /// - public GaussianSharpenProcessor(float sigma = 3f) + public GaussianSharpenProcessor(float sigma = 3F) { this.kernelSize = ((int)Math.Ceiling(sigma) * 2) + 1; - this.sigma = sigma; + this.Sigma = sigma; this.KernelX = this.CreateGaussianKernel(true); this.KernelY = this.CreateGaussianKernel(false); } @@ -48,7 +44,7 @@ namespace SixLabors.ImageSharp.Processing.Processors public GaussianSharpenProcessor(int radius) { this.kernelSize = (radius * 2) + 1; - this.sigma = radius; + this.Sigma = radius; this.KernelX = this.CreateGaussianKernel(true); this.KernelY = this.CreateGaussianKernel(false); } @@ -66,28 +62,28 @@ namespace SixLabors.ImageSharp.Processing.Processors public GaussianSharpenProcessor(float sigma, int radius) { this.kernelSize = (radius * 2) + 1; - this.sigma = sigma; + this.Sigma = sigma; this.KernelX = this.CreateGaussianKernel(true); this.KernelY = this.CreateGaussianKernel(false); } /// - /// Gets the sigma + /// Gets the sigma value representing the weight of the blur /// - public float Sigma => this.sigma; + public float Sigma { get; } /// /// Gets the horizontal gradient operator. /// - public Fast2DArray KernelX { get; } + public DenseMatrix KernelX { get; } /// /// Gets the vertical gradient operator. /// - public Fast2DArray KernelY { get; } + public DenseMatrix KernelY { get; } /// - protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) + protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { new Convolution2PassProcessor(this.KernelX, this.KernelY).Apply(source, sourceRectangle, configuration); } @@ -96,14 +92,14 @@ namespace SixLabors.ImageSharp.Processing.Processors /// Create a 1 dimensional Gaussian kernel using the Gaussian G(x) function /// /// Whether to calculate a horizontal kernel. - /// The - private Fast2DArray CreateGaussianKernel(bool horizontal) + /// The + private DenseMatrix CreateGaussianKernel(bool horizontal) { int size = this.kernelSize; - float weight = this.sigma; - Fast2DArray kernel = horizontal - ? new Fast2DArray(size, 1) - : new Fast2DArray(1, size); + float weight = this.Sigma; + DenseMatrix kernel = horizontal + ? new DenseMatrix(size, 1) + : new DenseMatrix(1, size); float sum = 0; @@ -159,7 +155,7 @@ namespace SixLabors.ImageSharp.Processing.Processors } } - // Normalise kernel so that the sum of all weights equals 1 + // Normalize kernel so that the sum of all weights equals 1 if (horizontal) { for (int i = 0; i < size; i++) diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/IEdgeDetectorProcessor.cs b/src/ImageSharp/Processing/Convolution/Processors/IEdgeDetectorProcessor.cs similarity index 73% rename from src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/IEdgeDetectorProcessor.cs rename to src/ImageSharp/Processing/Convolution/Processors/IEdgeDetectorProcessor.cs index 6208a24a46..486929e028 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/IEdgeDetectorProcessor.cs +++ b/src/ImageSharp/Processing/Convolution/Processors/IEdgeDetectorProcessor.cs @@ -1,10 +1,10 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; -namespace SixLabors.ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing.Convolution.Processors { /// /// Provides properties and methods allowing the detection of edges within an image. @@ -21,8 +21,8 @@ namespace SixLabors.ImageSharp.Processing public interface IEdgeDetectorProcessor { /// - /// Gets or sets a value indicating whether to convert the image to grayscale before performing edge detection. + /// Gets a value indicating whether to convert the image to grayscale before performing edge detection. /// - bool Grayscale { get; set; } + bool Grayscale { get; } } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Convolution/Processors/KayyaliKernels.cs b/src/ImageSharp/Processing/Convolution/Processors/KayyaliKernels.cs new file mode 100644 index 0000000000..e131cac38c --- /dev/null +++ b/src/ImageSharp/Processing/Convolution/Processors/KayyaliKernels.cs @@ -0,0 +1,35 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Primitives; + +namespace SixLabors.ImageSharp.Processing.Convolution.Processors +{ + /// + /// Contains the kernels used for Kayyali edge detection + /// + internal static class KayyaliKernels + { + /// + /// Gets the horizontal gradient operator. + /// + public static DenseMatrix KayyaliX => + new float[,] + { + { 6, 0, -6 }, + { 0, 0, 0 }, + { -6, 0, 6 } + }; + + /// + /// Gets the vertical gradient operator. + /// + public static DenseMatrix KayyaliY => + new float[,] + { + { -6, 0, 6 }, + { 0, 0, 0 }, + { 6, 0, -6 } + }; + } +} diff --git a/src/ImageSharp/Processing/Convolution/Processors/KayyaliProcessor.cs b/src/ImageSharp/Processing/Convolution/Processors/KayyaliProcessor.cs new file mode 100644 index 0000000000..357c6c3970 --- /dev/null +++ b/src/ImageSharp/Processing/Convolution/Processors/KayyaliProcessor.cs @@ -0,0 +1,24 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; + +namespace SixLabors.ImageSharp.Processing.Convolution.Processors +{ + /// + /// Applies edge detection processing to the image using the Kayyali operator filter. + /// + /// The pixel format. + internal class KayyaliProcessor : EdgeDetector2DProcessor + where TPixel : struct, IPixel + { + /// + /// Initializes a new instance of the class. + /// + /// Whether to convert the image to grayscale before performing edge detection. + public KayyaliProcessor(bool grayscale) + : base(KayyaliKernels.KayyaliX, KayyaliKernels.KayyaliY, grayscale) + { + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Convolution/Processors/KirschProcessor.cs b/src/ImageSharp/Processing/Convolution/Processors/KirschProcessor.cs new file mode 100644 index 0000000000..c9a21da0b7 --- /dev/null +++ b/src/ImageSharp/Processing/Convolution/Processors/KirschProcessor.cs @@ -0,0 +1,49 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Primitives; + +namespace SixLabors.ImageSharp.Processing.Convolution.Processors +{ + /// + /// Applies edge detection processing to the image using the Kirsch operator filter. + /// + /// The pixel format. + internal class KirschProcessor : EdgeDetectorCompassProcessor + where TPixel : struct, IPixel + { + /// + /// Initializes a new instance of the class. + /// + /// Whether to convert the image to grayscale before performing edge detection. + public KirschProcessor(bool grayscale) + : base(grayscale) + { + } + + /// + public override DenseMatrix North => KirshKernels.KirschNorth; + + /// + public override DenseMatrix NorthWest => KirshKernels.KirschNorthWest; + + /// + public override DenseMatrix West => KirshKernels.KirschWest; + + /// + public override DenseMatrix SouthWest => KirshKernels.KirschSouthWest; + + /// + public override DenseMatrix South => KirshKernels.KirschSouth; + + /// + public override DenseMatrix SouthEast => KirshKernels.KirschSouthEast; + + /// + public override DenseMatrix East => KirshKernels.KirschEast; + + /// + public override DenseMatrix NorthEast => KirshKernels.KirschNorthEast; + } +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Convolution/Processors/KirshKernels.cs b/src/ImageSharp/Processing/Convolution/Processors/KirshKernels.cs new file mode 100644 index 0000000000..8e52f8df4c --- /dev/null +++ b/src/ImageSharp/Processing/Convolution/Processors/KirshKernels.cs @@ -0,0 +1,101 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Primitives; + +namespace SixLabors.ImageSharp.Processing.Convolution.Processors +{ + /// + /// Contains the eight matrices used for Kirsh edge detection + /// + internal static class KirshKernels + { + /// + /// Gets the North gradient operator + /// + public static DenseMatrix KirschNorth => + new float[,] + { + { 5, 5, 5 }, + { -3, 0, -3 }, + { -3, -3, -3 } + }; + + /// + /// Gets the NorthWest gradient operator + /// + public static DenseMatrix KirschNorthWest => + new float[,] + { + { 5, 5, -3 }, + { 5, 0, -3 }, + { -3, -3, -3 } + }; + + /// + /// Gets the West gradient operator + /// + public static DenseMatrix KirschWest => + new float[,] + { + { 5, -3, -3 }, + { 5, 0, -3 }, + { 5, -3, -3 } + }; + + /// + /// Gets the SouthWest gradient operator + /// + public static DenseMatrix KirschSouthWest => + new float[,] + { + { -3, -3, -3 }, + { 5, 0, -3 }, + { 5, 5, -3 } + }; + + /// + /// Gets the South gradient operator + /// + public static DenseMatrix KirschSouth => + new float[,] + { + { -3, -3, -3 }, + { -3, 0, -3 }, + { 5, 5, 5 } + }; + + /// + /// Gets the SouthEast gradient operator + /// + public static DenseMatrix KirschSouthEast => + new float[,] + { + { -3, -3, -3 }, + { -3, 0, 5 }, + { -3, 5, 5 } + }; + + /// + /// Gets the East gradient operator + /// + public static DenseMatrix KirschEast => + new float[,] + { + { -3, -3, 5 }, + { -3, 0, 5 }, + { -3, -3, 5 } + }; + + /// + /// Gets the NorthEast gradient operator + /// + public static DenseMatrix KirschNorthEast => + new float[,] + { + { -3, 5, 5 }, + { -3, 0, 5 }, + { -3, -3, -3 } + }; + } +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Convolution/Processors/Laplacian3x3Processor.cs b/src/ImageSharp/Processing/Convolution/Processors/Laplacian3x3Processor.cs new file mode 100644 index 0000000000..657a93c816 --- /dev/null +++ b/src/ImageSharp/Processing/Convolution/Processors/Laplacian3x3Processor.cs @@ -0,0 +1,25 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; + +namespace SixLabors.ImageSharp.Processing.Convolution.Processors +{ + /// + /// Applies edge detection processing to the image using the Laplacian 3x3 operator filter. + /// + /// + /// The pixel format. + internal class Laplacian3x3Processor : EdgeDetectorProcessor + where TPixel : struct, IPixel + { + /// + /// Initializes a new instance of the class. + /// + /// Whether to convert the image to grayscale before performing edge detection. + public Laplacian3x3Processor(bool grayscale) + : base(LaplacianKernels.Laplacian3x3, grayscale) + { + } + } +} diff --git a/src/ImageSharp/Processing/Convolution/Processors/Laplacian5x5Processor.cs b/src/ImageSharp/Processing/Convolution/Processors/Laplacian5x5Processor.cs new file mode 100644 index 0000000000..5b44773add --- /dev/null +++ b/src/ImageSharp/Processing/Convolution/Processors/Laplacian5x5Processor.cs @@ -0,0 +1,25 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; + +namespace SixLabors.ImageSharp.Processing.Convolution.Processors +{ + /// + /// Applies edge detection processing to the image using the Laplacian 5x5 operator filter. + /// + /// + /// The pixel format. + internal class Laplacian5x5Processor : EdgeDetectorProcessor + where TPixel : struct, IPixel + { + /// + /// Initializes a new instance of the class. + /// + /// Whether to convert the image to grayscale before performing edge detection. + public Laplacian5x5Processor(bool grayscale) + : base(LaplacianKernels.Laplacian5x5, grayscale) + { + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Convolution/Processors/LaplacianKernelFactory.cs b/src/ImageSharp/Processing/Convolution/Processors/LaplacianKernelFactory.cs new file mode 100644 index 0000000000..053033432e --- /dev/null +++ b/src/ImageSharp/Processing/Convolution/Processors/LaplacianKernelFactory.cs @@ -0,0 +1,33 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Primitives; + +namespace SixLabors.ImageSharp.Processing.Convolution.Processors +{ + /// + /// A factory for creating Laplacian kernel matrices. + /// + internal static class LaplacianKernelFactory + { + /// + /// Creates a Laplacian matrix, 2nd derivative, of an arbitrary length. + /// + /// + /// The length of the matrix sides + /// The + public static DenseMatrix CreateKernel(uint length) + { + Guard.MustBeGreaterThanOrEqualTo(length, 3u, nameof(length)); + Guard.IsFalse(length % 2 == 0, nameof(length), "The kernel length must be an odd number."); + + var kernel = new DenseMatrix((int)length); + kernel.Fill(-1); + + int mid = (int)(length / 2); + kernel[mid, mid] = (length * length) - 1; + + return kernel; + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Convolution/Processors/LaplacianKernels.cs b/src/ImageSharp/Processing/Convolution/Processors/LaplacianKernels.cs new file mode 100644 index 0000000000..4077369802 --- /dev/null +++ b/src/ImageSharp/Processing/Convolution/Processors/LaplacianKernels.cs @@ -0,0 +1,36 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Primitives; + +namespace SixLabors.ImageSharp.Processing.Convolution.Processors +{ + /// + /// Contains Laplacian kernels of different sizes + /// + internal static class LaplacianKernels + { + /// + /// Gets the 3x3 Laplacian kernel + /// + public static DenseMatrix Laplacian3x3 => LaplacianKernelFactory.CreateKernel(3); + + /// + /// Gets the 5x5 Laplacian kernel + /// + public static DenseMatrix Laplacian5x5 => LaplacianKernelFactory.CreateKernel(5); + + /// + /// Gets the Laplacian of Gaussian kernel. + /// + public static DenseMatrix LaplacianOfGaussianXY => + new float[,] + { + { 0, 0, -1, 0, 0 }, + { 0, -1, -2, -1, 0 }, + { -1, -2, 16, -2, -1 }, + { 0, -1, -2, -1, 0 }, + { 0, 0, -1, 0, 0 } + }; + } +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Convolution/Processors/LaplacianOfGaussianProcessor.cs b/src/ImageSharp/Processing/Convolution/Processors/LaplacianOfGaussianProcessor.cs new file mode 100644 index 0000000000..e65e0d2152 --- /dev/null +++ b/src/ImageSharp/Processing/Convolution/Processors/LaplacianOfGaussianProcessor.cs @@ -0,0 +1,25 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; + +namespace SixLabors.ImageSharp.Processing.Convolution.Processors +{ + /// + /// Applies edge detection processing to the image using the Laplacian of Gaussian operator filter. + /// + /// + /// The pixel format. + internal class LaplacianOfGaussianProcessor : EdgeDetectorProcessor + where TPixel : struct, IPixel + { + /// + /// Initializes a new instance of the class. + /// + /// Whether to convert the image to grayscale before performing edge detection. + public LaplacianOfGaussianProcessor(bool grayscale) + : base(LaplacianKernels.LaplacianOfGaussianXY, grayscale) + { + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Convolution/Processors/PrewittKernels.cs b/src/ImageSharp/Processing/Convolution/Processors/PrewittKernels.cs new file mode 100644 index 0000000000..aba4d52c34 --- /dev/null +++ b/src/ImageSharp/Processing/Convolution/Processors/PrewittKernels.cs @@ -0,0 +1,35 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Primitives; + +namespace SixLabors.ImageSharp.Processing.Convolution.Processors +{ + /// + /// Contains the kernels used for Prewitt edge detection + /// + internal static class PrewittKernels + { + /// + /// Gets the horizontal gradient operator. + /// + public static DenseMatrix PrewittX => + new float[,] + { + { -1, 0, 1 }, + { -1, 0, 1 }, + { -1, 0, 1 } + }; + + /// + /// Gets the vertical gradient operator. + /// + public static DenseMatrix PrewittY => + new float[,] + { + { 1, 1, 1 }, + { 0, 0, 0 }, + { -1, -1, -1 } + }; + } +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Convolution/Processors/PrewittProcessor.cs b/src/ImageSharp/Processing/Convolution/Processors/PrewittProcessor.cs new file mode 100644 index 0000000000..5683d6f609 --- /dev/null +++ b/src/ImageSharp/Processing/Convolution/Processors/PrewittProcessor.cs @@ -0,0 +1,25 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; + +namespace SixLabors.ImageSharp.Processing.Convolution.Processors +{ + /// + /// Applies edge detection processing to the image using the Prewitt operator filter. + /// + /// + /// The pixel format. + internal class PrewittProcessor : EdgeDetector2DProcessor + where TPixel : struct, IPixel + { + /// + /// Initializes a new instance of the class. + /// + /// Whether to convert the image to grayscale before performing edge detection. + public PrewittProcessor(bool grayscale) + : base(PrewittKernels.PrewittX, PrewittKernels.PrewittY, grayscale) + { + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Convolution/Processors/RobertsCrossKernels.cs b/src/ImageSharp/Processing/Convolution/Processors/RobertsCrossKernels.cs new file mode 100644 index 0000000000..64d1fcea54 --- /dev/null +++ b/src/ImageSharp/Processing/Convolution/Processors/RobertsCrossKernels.cs @@ -0,0 +1,33 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Primitives; + +namespace SixLabors.ImageSharp.Processing.Convolution.Processors +{ + /// + /// Contains the kernels used for RobertsCross edge detection + /// + internal static class RobertsCrossKernels + { + /// + /// Gets the horizontal gradient operator. + /// + public static DenseMatrix RobertsCrossX => + new float[,] + { + { 1, 0 }, + { 0, -1 } + }; + + /// + /// Gets the vertical gradient operator. + /// + public static DenseMatrix RobertsCrossY => + new float[,] + { + { 0, 1 }, + { -1, 0 } + }; + } +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Convolution/Processors/RobertsCrossProcessor.cs b/src/ImageSharp/Processing/Convolution/Processors/RobertsCrossProcessor.cs new file mode 100644 index 0000000000..38d1fffc9a --- /dev/null +++ b/src/ImageSharp/Processing/Convolution/Processors/RobertsCrossProcessor.cs @@ -0,0 +1,25 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; + +namespace SixLabors.ImageSharp.Processing.Convolution.Processors +{ + /// + /// Applies edge detection processing to the image using the Roberts Cross operator filter. + /// + /// + /// The pixel format. + internal class RobertsCrossProcessor : EdgeDetector2DProcessor + where TPixel : struct, IPixel + { + /// + /// Initializes a new instance of the class. + /// + /// Whether to convert the image to grayscale before performing edge detection. + public RobertsCrossProcessor(bool grayscale) + : base(RobertsCrossKernels.RobertsCrossX, RobertsCrossKernels.RobertsCrossY, grayscale) + { + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Convolution/Processors/RobinsonKernels.cs b/src/ImageSharp/Processing/Convolution/Processors/RobinsonKernels.cs new file mode 100644 index 0000000000..9d440fcc0d --- /dev/null +++ b/src/ImageSharp/Processing/Convolution/Processors/RobinsonKernels.cs @@ -0,0 +1,101 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Primitives; + +namespace SixLabors.ImageSharp.Processing.Convolution.Processors +{ + /// + /// Contains the kernels used for Robinson edge detection + /// + internal static class RobinsonKernels + { + /// + /// Gets the North gradient operator + /// + public static DenseMatrix RobinsonNorth => + new float[,] + { + { 1, 2, 1 }, + { 0, 0, 0 }, + { -1, -2, -1 } + }; + + /// + /// Gets the NorthWest gradient operator + /// + public static DenseMatrix RobinsonNorthWest => + new float[,] + { + { 2, 1, 0 }, + { 1, 0, -1 }, + { 0, -1, -2 } + }; + + /// + /// Gets the West gradient operator + /// + public static DenseMatrix RobinsonWest => + new float[,] + { + { 1, 0, -1 }, + { 2, 0, -2 }, + { 1, 0, -1 } + }; + + /// + /// Gets the SouthWest gradient operator + /// + public static DenseMatrix RobinsonSouthWest => + new float[,] + { + { 0, -1, -2 }, + { 1, 0, -1 }, + { 2, 1, 0 } + }; + + /// + /// Gets the South gradient operator + /// + public static DenseMatrix RobinsonSouth => + new float[,] + { + { -1, -2, -1 }, + { 0, 0, 0 }, + { 1, 2, 1 } + }; + + /// + /// Gets the SouthEast gradient operator + /// + public static DenseMatrix RobinsonSouthEast => + new float[,] + { + { -2, -1, 0 }, + { -1, 0, 1 }, + { 0, 1, 2 } + }; + + /// + /// Gets the East gradient operator + /// + public static DenseMatrix RobinsonEast => + new float[,] + { + { -1, 0, 1 }, + { -2, 0, 2 }, + { -1, 0, 1 } + }; + + /// + /// Gets the NorthEast gradient operator + /// + public static DenseMatrix RobinsonNorthEast => + new float[,] + { + { 0, 1, 2 }, + { -1, 0, 1 }, + { -2, -1, 0 } + }; + } +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Convolution/Processors/RobinsonProcessor.cs b/src/ImageSharp/Processing/Convolution/Processors/RobinsonProcessor.cs new file mode 100644 index 0000000000..f129b1daa2 --- /dev/null +++ b/src/ImageSharp/Processing/Convolution/Processors/RobinsonProcessor.cs @@ -0,0 +1,50 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Primitives; + +namespace SixLabors.ImageSharp.Processing.Convolution.Processors +{ + /// + /// Applies edge detection processing to the image using the Robinson operator filter. + /// + /// + /// The pixel format. + internal class RobinsonProcessor : EdgeDetectorCompassProcessor + where TPixel : struct, IPixel + { + /// + /// Initializes a new instance of the class. + /// + /// Whether to convert the image to grayscale before performing edge detection. + public RobinsonProcessor(bool grayscale) + : base(grayscale) + { + } + + /// + public override DenseMatrix North => RobinsonKernels.RobinsonNorth; + + /// + public override DenseMatrix NorthWest => RobinsonKernels.RobinsonNorthWest; + + /// + public override DenseMatrix West => RobinsonKernels.RobinsonWest; + + /// + public override DenseMatrix SouthWest => RobinsonKernels.RobinsonSouthWest; + + /// + public override DenseMatrix South => RobinsonKernels.RobinsonSouth; + + /// + public override DenseMatrix SouthEast => RobinsonKernels.RobinsonSouthEast; + + /// + public override DenseMatrix East => RobinsonKernels.RobinsonEast; + + /// + public override DenseMatrix NorthEast => RobinsonKernels.RobinsonNorthEast; + } +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Convolution/Processors/ScharrKernels.cs b/src/ImageSharp/Processing/Convolution/Processors/ScharrKernels.cs new file mode 100644 index 0000000000..c309e4cec5 --- /dev/null +++ b/src/ImageSharp/Processing/Convolution/Processors/ScharrKernels.cs @@ -0,0 +1,35 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Primitives; + +namespace SixLabors.ImageSharp.Processing.Convolution.Processors +{ + /// + /// Contains the kernels used for Scharr edge detection + /// + internal static class ScharrKernels + { + /// + /// Gets the horizontal gradient operator. + /// + public static DenseMatrix ScharrX => + new float[,] + { + { -3, 0, 3 }, + { -10, 0, 10 }, + { -3, 0, 3 } + }; + + /// + /// Gets the vertical gradient operator. + /// + public static DenseMatrix ScharrY => + new float[,] + { + { 3, 10, 3 }, + { 0, 0, 0 }, + { -3, -10, -3 } + }; + } +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Convolution/Processors/ScharrProcessor.cs b/src/ImageSharp/Processing/Convolution/Processors/ScharrProcessor.cs new file mode 100644 index 0000000000..c101d092de --- /dev/null +++ b/src/ImageSharp/Processing/Convolution/Processors/ScharrProcessor.cs @@ -0,0 +1,25 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; + +namespace SixLabors.ImageSharp.Processing.Convolution.Processors +{ + /// + /// Applies edge detection processing to the image using the Scharr operator filter. + /// + /// + /// The pixel format. + internal class ScharrProcessor : EdgeDetector2DProcessor + where TPixel : struct, IPixel + { + /// + /// Initializes a new instance of the class. + /// + /// Whether to convert the image to grayscale before performing edge detection. + public ScharrProcessor(bool grayscale) + : base(ScharrKernels.ScharrX, ScharrKernels.ScharrY, grayscale) + { + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Convolution/Processors/SobelKernels.cs b/src/ImageSharp/Processing/Convolution/Processors/SobelKernels.cs new file mode 100644 index 0000000000..626226c660 --- /dev/null +++ b/src/ImageSharp/Processing/Convolution/Processors/SobelKernels.cs @@ -0,0 +1,35 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Primitives; + +namespace SixLabors.ImageSharp.Processing.Convolution.Processors +{ + /// + /// Contains the kernels used for Sobel edge detection + /// + internal static class SobelKernels + { + /// + /// Gets the horizontal gradient operator. + /// + public static DenseMatrix SobelX => + new float[,] + { + { -1, 0, 1 }, + { -2, 0, 2 }, + { -1, 0, 1 } + }; + + /// + /// Gets the vertical gradient operator. + /// + public static DenseMatrix SobelY => + new float[,] + { + { -1, -2, -1 }, + { 0, 0, 0 }, + { 1, 2, 1 } + }; + } +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Convolution/Processors/SobelProcessor.cs b/src/ImageSharp/Processing/Convolution/Processors/SobelProcessor.cs new file mode 100644 index 0000000000..bf97c67d7f --- /dev/null +++ b/src/ImageSharp/Processing/Convolution/Processors/SobelProcessor.cs @@ -0,0 +1,26 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; + +namespace SixLabors.ImageSharp.Processing.Convolution.Processors +{ + /// + /// The Sobel operator filter. + /// + /// + /// The pixel format. + internal class SobelProcessor : EdgeDetector2DProcessor + where TPixel : struct, IPixel + { + /// + /// Initializes a new instance of the class. + /// + /// Whether to convert the image to grayscale before performing edge detection. + public SobelProcessor(bool grayscale) + : base(SobelKernels.SobelX, SobelKernels.SobelY, grayscale) + { + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/DefaultInternalImageProcessorContext.cs b/src/ImageSharp/Processing/DefaultInternalImageProcessorContext.cs similarity index 92% rename from src/ImageSharp/DefaultInternalImageProcessorContext.cs rename to src/ImageSharp/Processing/DefaultInternalImageProcessorContext.cs index 7ccc65e27e..b71430e13e 100644 --- a/src/ImageSharp/DefaultInternalImageProcessorContext.cs +++ b/src/ImageSharp/Processing/DefaultInternalImageProcessorContext.cs @@ -2,13 +2,12 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Helpers; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing { /// /// Performs processor application operations on the source image @@ -81,9 +80,6 @@ namespace SixLabors.ImageSharp return this.ApplyProcessor(processor, this.GetCurrentBounds()); } - private Rectangle GetCurrentBounds() - { - return this.destination?.Bounds() ?? this.source.Bounds(); - } + private Rectangle GetCurrentBounds() => this.destination?.Bounds() ?? this.source.Bounds(); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Delegate.cs b/src/ImageSharp/Processing/Delegate.cs deleted file mode 100644 index b390e46ae9..0000000000 --- a/src/ImageSharp/Processing/Delegate.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; -using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing; - -namespace SixLabors.ImageSharp -{ - /// - /// Extension methods for the type. - /// - public static partial class ImageExtensions - { - /// - /// Applies the given operation to the mutable image. - /// Useful when we need to extract information like Width/Height to parameterize the next operation working on the chain. - /// To achieve this the method actually implements an "inline" with as it's processing logic. - /// - /// The pixel format. - /// The image to mutate. - /// The operation to perform on the source. - /// The to allow chaining of operations. - public static IImageProcessingContext Apply(this IImageProcessingContext source, Action> operation) - where TPixel : struct, IPixel - => source.ApplyProcessor(new DelegateProcessor(operation)); - } -} diff --git a/src/ImageSharp/Dithering/DHALF.TXT b/src/ImageSharp/Processing/Dithering/DHALF.TXT similarity index 100% rename from src/ImageSharp/Dithering/DHALF.TXT rename to src/ImageSharp/Processing/Dithering/DHALF.TXT diff --git a/src/ImageSharp/Dithering/DITHER.TXT b/src/ImageSharp/Processing/Dithering/DITHER.TXT similarity index 100% rename from src/ImageSharp/Dithering/DITHER.TXT rename to src/ImageSharp/Processing/Dithering/DITHER.TXT diff --git a/src/ImageSharp/Processing/Dithering/Diffuse.cs b/src/ImageSharp/Processing/Dithering/DiffuseExtensions.cs similarity index 65% rename from src/ImageSharp/Processing/Dithering/Diffuse.cs rename to src/ImageSharp/Processing/Dithering/DiffuseExtensions.cs index e6b82d3134..7ae8ec01ef 100644 --- a/src/ImageSharp/Processing/Dithering/Diffuse.cs +++ b/src/ImageSharp/Processing/Dithering/DiffuseExtensions.cs @@ -1,18 +1,39 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Dithering; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion; +using SixLabors.ImageSharp.Processing.Dithering.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Dithering { /// - /// Extension methods for the type. + /// Adds diffusion extensions to the type. /// - public static partial class ImageExtensions + public static class DiffuseExtensions { + /// + /// Dithers the image reducing it to a web-safe palette using error diffusion. + /// + /// The pixel format. + /// The image this method extends. + /// The . + public static IImageProcessingContext Diffuse(this IImageProcessingContext source) + where TPixel : struct, IPixel + => Diffuse(source, DiffuseMode.FloydSteinberg, .5F); + + /// + /// Dithers the image reducing it to a web-safe palette using error diffusion. + /// + /// The pixel format. + /// The image this method extends. + /// The threshold to apply binarization of the image. Must be between 0 and 1. + /// The . + public static IImageProcessingContext Diffuse(this IImageProcessingContext source, float threshold) + where TPixel : struct, IPixel + => Diffuse(source, DiffuseMode.FloydSteinberg, threshold); + /// /// Dithers the image reducing it to a web-safe palette using error diffusion. /// @@ -23,10 +44,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Diffuse(this IImageProcessingContext source, IErrorDiffuser diffuser, float threshold) where TPixel : struct, IPixel - { - source.ApplyProcessor(new ErrorDiffusionPaletteProcessor(diffuser, threshold)); - return source; - } + => source.ApplyProcessor(new ErrorDiffusionPaletteProcessor(diffuser, threshold)); /// /// Dithers the image reducing it to a web-safe palette using error diffusion. @@ -41,10 +59,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Diffuse(this IImageProcessingContext source, IErrorDiffuser diffuser, float threshold, Rectangle rectangle) where TPixel : struct, IPixel - { - source.ApplyProcessor(new ErrorDiffusionPaletteProcessor(diffuser, threshold), rectangle); - return source; - } + => source.ApplyProcessor(new ErrorDiffusionPaletteProcessor(diffuser, threshold), rectangle); /// /// Dithers the image reducing it to the given palette using error diffusion. @@ -57,10 +72,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Diffuse(this IImageProcessingContext source, IErrorDiffuser diffuser, float threshold, TPixel[] palette) where TPixel : struct, IPixel - { - source.ApplyProcessor(new ErrorDiffusionPaletteProcessor(diffuser, threshold, palette)); - return source; - } + => source.ApplyProcessor(new ErrorDiffusionPaletteProcessor(diffuser, threshold, palette)); /// /// Dithers the image reducing it to the given palette using error diffusion. @@ -76,9 +88,6 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Diffuse(this IImageProcessingContext source, IErrorDiffuser diffuser, float threshold, TPixel[] palette, Rectangle rectangle) where TPixel : struct, IPixel - { - source.ApplyProcessor(new ErrorDiffusionPaletteProcessor(diffuser, threshold, palette), rectangle); - return source; - } + => source.ApplyProcessor(new ErrorDiffusionPaletteProcessor(diffuser, threshold, palette), rectangle); } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/KnownDiffusers.cs b/src/ImageSharp/Processing/Dithering/DiffuseMode.cs similarity index 93% rename from src/ImageSharp/Dithering/ErrorDiffusion/KnownDiffusers.cs rename to src/ImageSharp/Processing/Dithering/DiffuseMode.cs index c75530b8e7..cc74f1230f 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/KnownDiffusers.cs +++ b/src/ImageSharp/Processing/Dithering/DiffuseMode.cs @@ -1,12 +1,14 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Dithering +using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion; + +namespace SixLabors.ImageSharp.Processing.Dithering { /// /// Contains reusable static instances of known error diffusion algorithms /// - public static class KnownDiffusers + public static class DiffuseMode { /// /// Gets the error diffuser that implements the Atkinson algorithm. diff --git a/src/ImageSharp/Processing/Dithering/Dither.cs b/src/ImageSharp/Processing/Dithering/DitherExtensions.cs similarity index 71% rename from src/ImageSharp/Processing/Dithering/Dither.cs rename to src/ImageSharp/Processing/Dithering/DitherExtensions.cs index 85fdef24b5..31ef12a0ac 100644 --- a/src/ImageSharp/Processing/Dithering/Dither.cs +++ b/src/ImageSharp/Processing/Dithering/DitherExtensions.cs @@ -1,18 +1,28 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Dithering; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Dithering.Ordered; +using SixLabors.ImageSharp.Processing.Dithering.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Dithering { /// - /// Extension methods for the type. + /// Adds dithering extensions to the type. /// - public static partial class ImageExtensions + public static class DitherExtensions { + /// + /// Dithers the image reducing it to a web-safe palette using Bayer4x4 ordered dithering. + /// + /// The pixel format. + /// The image this method extends. + /// The . + public static IImageProcessingContext Dither(this IImageProcessingContext source) + where TPixel : struct, IPixel + => Dither(source, DitherMode.BayerDither4x4); + /// /// Dithers the image reducing it to a web-safe palette using ordered dithering. /// @@ -22,10 +32,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Dither(this IImageProcessingContext source, IOrderedDither dither) where TPixel : struct, IPixel - { - source.ApplyProcessor(new OrderedDitherPaletteProcessor(dither)); - return source; - } + => source.ApplyProcessor(new OrderedDitherPaletteProcessor(dither)); /// /// Dithers the image reducing it to the given palette using ordered dithering. @@ -37,10 +44,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Dither(this IImageProcessingContext source, IOrderedDither dither, TPixel[] palette) where TPixel : struct, IPixel - { - source.ApplyProcessor(new OrderedDitherPaletteProcessor(dither, palette)); - return source; - } + => source.ApplyProcessor(new OrderedDitherPaletteProcessor(dither, palette)); /// /// Dithers the image reducing it to a web-safe palette using ordered dithering. @@ -54,10 +58,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Dither(this IImageProcessingContext source, IOrderedDither dither, Rectangle rectangle) where TPixel : struct, IPixel - { - source.ApplyProcessor(new OrderedDitherPaletteProcessor(dither), rectangle); - return source; - } + => source.ApplyProcessor(new OrderedDitherPaletteProcessor(dither), rectangle); /// /// Dithers the image reducing it to the given palette using ordered dithering. @@ -72,9 +73,6 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Dither(this IImageProcessingContext source, IOrderedDither dither, TPixel[] palette, Rectangle rectangle) where TPixel : struct, IPixel - { - source.ApplyProcessor(new OrderedDitherPaletteProcessor(dither, palette), rectangle); - return source; - } + => source.ApplyProcessor(new OrderedDitherPaletteProcessor(dither, palette), rectangle); } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Dithering/Ordered/KnownDitherers.cs b/src/ImageSharp/Processing/Dithering/DitherMode.cs similarity index 88% rename from src/ImageSharp/Dithering/Ordered/KnownDitherers.cs rename to src/ImageSharp/Processing/Dithering/DitherMode.cs index e58cbad8ab..f5122608c1 100644 --- a/src/ImageSharp/Dithering/Ordered/KnownDitherers.cs +++ b/src/ImageSharp/Processing/Dithering/DitherMode.cs @@ -1,12 +1,14 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Dithering +using SixLabors.ImageSharp.Processing.Dithering.Ordered; + +namespace SixLabors.ImageSharp.Processing.Dithering { /// /// Contains reusable static instances of known ordered dither matrices /// - public class KnownDitherers + public class DitherMode { /// /// Gets the order ditherer using the 2x2 Bayer dithering matrix diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/AtkinsonDiffuser.cs b/src/ImageSharp/Processing/Dithering/ErrorDiffusion/AtkinsonDiffuser.cs similarity index 82% rename from src/ImageSharp/Dithering/ErrorDiffusion/AtkinsonDiffuser.cs rename to src/ImageSharp/Processing/Dithering/ErrorDiffusion/AtkinsonDiffuser.cs index 3899b14cc9..2b13980fc4 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/AtkinsonDiffuser.cs +++ b/src/ImageSharp/Processing/Dithering/ErrorDiffusion/AtkinsonDiffuser.cs @@ -1,10 +1,9 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Dithering.Base; -using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.Primitives; -namespace SixLabors.ImageSharp.Dithering +namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion { /// /// Applies error diffusion based dithering using the Atkinson image dithering algorithm. @@ -15,7 +14,7 @@ namespace SixLabors.ImageSharp.Dithering /// /// The diffusion matrix /// - private static readonly Fast2DArray AtkinsonMatrix = + private static readonly DenseMatrix AtkinsonMatrix = new float[,] { { 0, 0, 1, 1 }, diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/BurksDiffuser.cs b/src/ImageSharp/Processing/Dithering/ErrorDiffusion/BurksDiffuser.cs similarity index 81% rename from src/ImageSharp/Dithering/ErrorDiffusion/BurksDiffuser.cs rename to src/ImageSharp/Processing/Dithering/ErrorDiffusion/BurksDiffuser.cs index 4d9f4d3c4f..b4b439c9a8 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/BurksDiffuser.cs +++ b/src/ImageSharp/Processing/Dithering/ErrorDiffusion/BurksDiffuser.cs @@ -1,10 +1,9 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Dithering.Base; -using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.Primitives; -namespace SixLabors.ImageSharp.Dithering +namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion { /// /// Applies error diffusion based dithering using the Burks image dithering algorithm. @@ -15,7 +14,7 @@ namespace SixLabors.ImageSharp.Dithering /// /// The diffusion matrix /// - private static readonly Fast2DArray BurksMatrix = + private static readonly DenseMatrix BurksMatrix = new float[,] { { 0, 0, 0, 8, 4 }, diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/ErrorDiffuserBase.cs b/src/ImageSharp/Processing/Dithering/ErrorDiffusion/ErrorDiffuserBase.cs similarity index 92% rename from src/ImageSharp/Dithering/ErrorDiffusion/ErrorDiffuserBase.cs rename to src/ImageSharp/Processing/Dithering/ErrorDiffusion/ErrorDiffuserBase.cs index 8f448198b0..3bc1df0bb2 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/ErrorDiffuserBase.cs +++ b/src/ImageSharp/Processing/Dithering/ErrorDiffusion/ErrorDiffuserBase.cs @@ -5,10 +5,10 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Primitives; -namespace SixLabors.ImageSharp.Dithering.Base +namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion { /// /// The base class for performing error diffusion based dithering. @@ -38,21 +38,21 @@ namespace SixLabors.ImageSharp.Dithering.Base /// /// The diffusion matrix /// - private readonly Fast2DArray matrix; + private readonly DenseMatrix matrix; /// /// Initializes a new instance of the class. /// /// The dithering matrix. /// The divisor. - internal ErrorDiffuserBase(Fast2DArray matrix, byte divisor) + internal ErrorDiffuserBase(DenseMatrix matrix, byte divisor) { Guard.NotNull(matrix, nameof(matrix)); Guard.MustBeGreaterThan(divisor, 0, nameof(divisor)); this.matrix = matrix; - this.matrixWidth = this.matrix.Width; - this.matrixHeight = this.matrix.Height; + this.matrixWidth = this.matrix.Columns; + this.matrixHeight = this.matrix.Rows; this.divisorVector = new Vector4(divisor); this.startingOffset = 0; diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/FloydSteinbergDiffuser.cs b/src/ImageSharp/Processing/Dithering/ErrorDiffusion/FloydSteinbergDiffuser.cs similarity index 82% rename from src/ImageSharp/Dithering/ErrorDiffusion/FloydSteinbergDiffuser.cs rename to src/ImageSharp/Processing/Dithering/ErrorDiffusion/FloydSteinbergDiffuser.cs index 6457fbe01e..290d77864e 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/FloydSteinbergDiffuser.cs +++ b/src/ImageSharp/Processing/Dithering/ErrorDiffusion/FloydSteinbergDiffuser.cs @@ -1,10 +1,9 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Dithering.Base; -using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.Primitives; -namespace SixLabors.ImageSharp.Dithering +namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion { /// /// Applies error diffusion based dithering using the Floyd–Steinberg image dithering algorithm. @@ -15,7 +14,7 @@ namespace SixLabors.ImageSharp.Dithering /// /// The diffusion matrix /// - private static readonly Fast2DArray FloydSteinbergMatrix = + private static readonly DenseMatrix FloydSteinbergMatrix = new float[,] { { 0, 0, 7 }, diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/IErrorDiffuser.cs b/src/ImageSharp/Processing/Dithering/ErrorDiffusion/IErrorDiffuser.cs similarity index 94% rename from src/ImageSharp/Dithering/ErrorDiffusion/IErrorDiffuser.cs rename to src/ImageSharp/Processing/Dithering/ErrorDiffusion/IErrorDiffuser.cs index dabc4e6822..795aa65062 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/IErrorDiffuser.cs +++ b/src/ImageSharp/Processing/Dithering/ErrorDiffusion/IErrorDiffuser.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Dithering +namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion { /// /// Encapsulates properties and methods required to perform diffused error dithering on an image. diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/JarvisJudiceNinkeDiffuser.cs b/src/ImageSharp/Processing/Dithering/ErrorDiffusion/JarvisJudiceNinkeDiffuser.cs similarity index 83% rename from src/ImageSharp/Dithering/ErrorDiffusion/JarvisJudiceNinkeDiffuser.cs rename to src/ImageSharp/Processing/Dithering/ErrorDiffusion/JarvisJudiceNinkeDiffuser.cs index 30e09b47a9..816447ec9e 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/JarvisJudiceNinkeDiffuser.cs +++ b/src/ImageSharp/Processing/Dithering/ErrorDiffusion/JarvisJudiceNinkeDiffuser.cs @@ -1,10 +1,9 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Dithering.Base; -using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.Primitives; -namespace SixLabors.ImageSharp.Dithering +namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion { /// /// Applies error diffusion based dithering using the JarvisJudiceNinke image dithering algorithm. @@ -15,7 +14,7 @@ namespace SixLabors.ImageSharp.Dithering /// /// The diffusion matrix /// - private static readonly Fast2DArray JarvisJudiceNinkeMatrix = + private static readonly DenseMatrix JarvisJudiceNinkeMatrix = new float[,] { { 0, 0, 0, 7, 5 }, diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/Sierra2Diffuser.cs b/src/ImageSharp/Processing/Dithering/ErrorDiffusion/Sierra2Diffuser.cs similarity index 81% rename from src/ImageSharp/Dithering/ErrorDiffusion/Sierra2Diffuser.cs rename to src/ImageSharp/Processing/Dithering/ErrorDiffusion/Sierra2Diffuser.cs index c472d25b0d..0b7e13c84a 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/Sierra2Diffuser.cs +++ b/src/ImageSharp/Processing/Dithering/ErrorDiffusion/Sierra2Diffuser.cs @@ -1,10 +1,9 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Dithering.Base; -using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.Primitives; -namespace SixLabors.ImageSharp.Dithering +namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion { /// /// Applies error diffusion based dithering using the Sierra2 image dithering algorithm. @@ -15,7 +14,7 @@ namespace SixLabors.ImageSharp.Dithering /// /// The diffusion matrix /// - private static readonly Fast2DArray Sierra2Matrix = + private static readonly DenseMatrix Sierra2Matrix = new float[,] { { 0, 0, 0, 4, 3 }, diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/Sierra3Diffuser.cs b/src/ImageSharp/Processing/Dithering/ErrorDiffusion/Sierra3Diffuser.cs similarity index 82% rename from src/ImageSharp/Dithering/ErrorDiffusion/Sierra3Diffuser.cs rename to src/ImageSharp/Processing/Dithering/ErrorDiffusion/Sierra3Diffuser.cs index c19ab2aaac..937b3a8cbd 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/Sierra3Diffuser.cs +++ b/src/ImageSharp/Processing/Dithering/ErrorDiffusion/Sierra3Diffuser.cs @@ -1,10 +1,9 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Dithering.Base; -using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.Primitives; -namespace SixLabors.ImageSharp.Dithering +namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion { /// /// Applies error diffusion based dithering using the Sierra3 image dithering algorithm. @@ -15,7 +14,7 @@ namespace SixLabors.ImageSharp.Dithering /// /// The diffusion matrix /// - private static readonly Fast2DArray Sierra3Matrix = + private static readonly DenseMatrix Sierra3Matrix = new float[,] { { 0, 0, 0, 5, 3 }, diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/SierraLiteDiffuser.cs b/src/ImageSharp/Processing/Dithering/ErrorDiffusion/SierraLiteDiffuser.cs similarity index 81% rename from src/ImageSharp/Dithering/ErrorDiffusion/SierraLiteDiffuser.cs rename to src/ImageSharp/Processing/Dithering/ErrorDiffusion/SierraLiteDiffuser.cs index 263bae568a..c9594e9e21 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/SierraLiteDiffuser.cs +++ b/src/ImageSharp/Processing/Dithering/ErrorDiffusion/SierraLiteDiffuser.cs @@ -1,10 +1,9 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Dithering.Base; -using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.Primitives; -namespace SixLabors.ImageSharp.Dithering +namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion { /// /// Applies error diffusion based dithering using the SierraLite image dithering algorithm. @@ -15,7 +14,7 @@ namespace SixLabors.ImageSharp.Dithering /// /// The diffusion matrix /// - private static readonly Fast2DArray SierraLiteMatrix = + private static readonly DenseMatrix SierraLiteMatrix = new float[,] { { 0, 0, 2 }, diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/StevensonArceDiffuser.cs b/src/ImageSharp/Processing/Dithering/ErrorDiffusion/StevensonArceDiffuser.cs similarity index 82% rename from src/ImageSharp/Dithering/ErrorDiffusion/StevensonArceDiffuser.cs rename to src/ImageSharp/Processing/Dithering/ErrorDiffusion/StevensonArceDiffuser.cs index 0f0338ac72..749502a034 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/StevensonArceDiffuser.cs +++ b/src/ImageSharp/Processing/Dithering/ErrorDiffusion/StevensonArceDiffuser.cs @@ -1,10 +1,9 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Dithering.Base; -using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.Primitives; -namespace SixLabors.ImageSharp.Dithering +namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion { /// /// Applies error diffusion based dithering using the Stevenson-Arce image dithering algorithm. @@ -14,7 +13,7 @@ namespace SixLabors.ImageSharp.Dithering /// /// The diffusion matrix /// - private static readonly Fast2DArray StevensonArceMatrix = + private static readonly DenseMatrix StevensonArceMatrix = new float[,] { { 0, 0, 0, 0, 0, 32, 0 }, @@ -31,4 +30,4 @@ namespace SixLabors.ImageSharp.Dithering { } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/StuckiDiffuser.cs b/src/ImageSharp/Processing/Dithering/ErrorDiffusion/StuckiDiffuser.cs similarity index 81% rename from src/ImageSharp/Dithering/ErrorDiffusion/StuckiDiffuser.cs rename to src/ImageSharp/Processing/Dithering/ErrorDiffusion/StuckiDiffuser.cs index 0717695065..077c02cbd4 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/StuckiDiffuser.cs +++ b/src/ImageSharp/Processing/Dithering/ErrorDiffusion/StuckiDiffuser.cs @@ -1,10 +1,9 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Dithering.Base; -using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.Primitives; -namespace SixLabors.ImageSharp.Dithering +namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion { /// /// Applies error diffusion based dithering using the Stucki image dithering algorithm. @@ -15,7 +14,7 @@ namespace SixLabors.ImageSharp.Dithering /// /// The diffusion matrix /// - private static readonly Fast2DArray StuckiMatrix = + private static readonly DenseMatrix StuckiMatrix = new float[,] { { 0, 0, 0, 8, 4 }, diff --git a/src/ImageSharp/Dithering/Ordered/BayerDither2x2.cs b/src/ImageSharp/Processing/Dithering/Ordered/BayerDither2x2.cs similarity index 88% rename from src/ImageSharp/Dithering/Ordered/BayerDither2x2.cs rename to src/ImageSharp/Processing/Dithering/Ordered/BayerDither2x2.cs index 1d844c8a79..2d674787a2 100644 --- a/src/ImageSharp/Dithering/Ordered/BayerDither2x2.cs +++ b/src/ImageSharp/Processing/Dithering/Ordered/BayerDither2x2.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Dithering +namespace SixLabors.ImageSharp.Processing.Dithering.Ordered { /// /// Applies order dithering using the 2x2 Bayer dithering matrix. diff --git a/src/ImageSharp/Dithering/Ordered/BayerDither4x4.cs b/src/ImageSharp/Processing/Dithering/Ordered/BayerDither4x4.cs similarity index 88% rename from src/ImageSharp/Dithering/Ordered/BayerDither4x4.cs rename to src/ImageSharp/Processing/Dithering/Ordered/BayerDither4x4.cs index 4e9f20beb9..edc57441a3 100644 --- a/src/ImageSharp/Dithering/Ordered/BayerDither4x4.cs +++ b/src/ImageSharp/Processing/Dithering/Ordered/BayerDither4x4.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Dithering +namespace SixLabors.ImageSharp.Processing.Dithering.Ordered { /// /// Applies order dithering using the 4x4 Bayer dithering matrix. diff --git a/src/ImageSharp/Dithering/Ordered/BayerDither8x8.cs b/src/ImageSharp/Processing/Dithering/Ordered/BayerDither8x8.cs similarity index 88% rename from src/ImageSharp/Dithering/Ordered/BayerDither8x8.cs rename to src/ImageSharp/Processing/Dithering/Ordered/BayerDither8x8.cs index 3ff179a06a..b79216208b 100644 --- a/src/ImageSharp/Dithering/Ordered/BayerDither8x8.cs +++ b/src/ImageSharp/Processing/Dithering/Ordered/BayerDither8x8.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Dithering +namespace SixLabors.ImageSharp.Processing.Dithering.Ordered { /// /// Applies order dithering using the 8x8 Bayer dithering matrix. diff --git a/src/ImageSharp/Dithering/Ordered/IOrderedDither.cs b/src/ImageSharp/Processing/Dithering/Ordered/IOrderedDither.cs similarity index 95% rename from src/ImageSharp/Dithering/Ordered/IOrderedDither.cs rename to src/ImageSharp/Processing/Dithering/Ordered/IOrderedDither.cs index 339f2861d9..29b96ab45a 100644 --- a/src/ImageSharp/Dithering/Ordered/IOrderedDither.cs +++ b/src/ImageSharp/Processing/Dithering/Ordered/IOrderedDither.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Dithering +namespace SixLabors.ImageSharp.Processing.Dithering.Ordered { /// /// Encapsulates properties and methods required to perform ordered dithering on an image. diff --git a/src/ImageSharp/Dithering/Ordered/OrderedDither.cs b/src/ImageSharp/Processing/Dithering/Ordered/OrderedDither.cs similarity index 72% rename from src/ImageSharp/Dithering/Ordered/OrderedDither.cs rename to src/ImageSharp/Processing/Dithering/Ordered/OrderedDither.cs index c07b185bbe..9fd274ab78 100644 --- a/src/ImageSharp/Dithering/Ordered/OrderedDither.cs +++ b/src/ImageSharp/Processing/Dithering/Ordered/OrderedDither.cs @@ -1,17 +1,17 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Primitives; -namespace SixLabors.ImageSharp.Dithering +namespace SixLabors.ImageSharp.Processing.Dithering.Ordered { /// /// An ordered dithering matrix with equal sides of arbitrary length /// public class OrderedDither : IOrderedDither { - private readonly Fast2DArray thresholdMatrix; + private readonly DenseMatrix thresholdMatrix; private readonly int modulusX; private readonly int modulusY; @@ -21,17 +21,17 @@ namespace SixLabors.ImageSharp.Dithering /// The length of the matrix sides public OrderedDither(uint length) { - Fast2DArray ditherMatrix = OrderedDitherFactory.CreateDitherMatrix(length); - this.modulusX = ditherMatrix.Width; - this.modulusY = ditherMatrix.Height; + DenseMatrix ditherMatrix = OrderedDitherFactory.CreateDitherMatrix(length); + this.modulusX = ditherMatrix.Columns; + this.modulusY = ditherMatrix.Rows; // Adjust the matrix range for 0-255 - // It looks like it's actually possible to dither an image using it's own colors. We should investigate for V2 + // TODO: It looks like it's actually possible to dither an image using it's own colors. We should investigate for V2 // https://stackoverflow.com/questions/12422407/monochrome-dithering-in-javascript-bayer-atkinson-floyd-steinberg int multiplier = 256 / ditherMatrix.Count; - for (int y = 0; y < ditherMatrix.Height; y++) + for (int y = 0; y < ditherMatrix.Rows; y++) { - for (int x = 0; x < ditherMatrix.Width; x++) + for (int x = 0; x < ditherMatrix.Columns; x++) { ditherMatrix[y, x] = (uint)((ditherMatrix[y, x] + 1) * multiplier) - 1; } diff --git a/src/ImageSharp/Dithering/Ordered/OrderedDither3x3.cs b/src/ImageSharp/Processing/Dithering/Ordered/OrderedDither3x3.cs similarity index 88% rename from src/ImageSharp/Dithering/Ordered/OrderedDither3x3.cs rename to src/ImageSharp/Processing/Dithering/Ordered/OrderedDither3x3.cs index 0436b35e9c..dd20817cf6 100644 --- a/src/ImageSharp/Dithering/Ordered/OrderedDither3x3.cs +++ b/src/ImageSharp/Processing/Dithering/Ordered/OrderedDither3x3.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Dithering +namespace SixLabors.ImageSharp.Processing.Dithering.Ordered { /// /// Applies order dithering using the 3x3 dithering matrix. diff --git a/src/ImageSharp/Dithering/Ordered/OrderedDitherFactory.cs b/src/ImageSharp/Processing/Dithering/Ordered/OrderedDitherFactory.cs similarity index 87% rename from src/ImageSharp/Dithering/Ordered/OrderedDitherFactory.cs rename to src/ImageSharp/Processing/Dithering/Ordered/OrderedDitherFactory.cs index fc9ac25517..7538aa50ed 100644 --- a/src/ImageSharp/Dithering/Ordered/OrderedDitherFactory.cs +++ b/src/ImageSharp/Processing/Dithering/Ordered/OrderedDitherFactory.cs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0. using System.Runtime.CompilerServices; -using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.Primitives; -namespace SixLabors.ImageSharp.Dithering +namespace SixLabors.ImageSharp.Processing.Dithering.Ordered { /// /// A factory for creating ordered dither matrices. @@ -16,8 +16,8 @@ namespace SixLabors.ImageSharp.Dithering /// /// /// The length of the matrix sides - /// The - public static Fast2DArray CreateDitherMatrix(uint length) + /// The + public static DenseMatrix CreateDitherMatrix(uint length) { // Calculate the the logarithm of length to the base 2 uint exponent = 0; @@ -30,7 +30,7 @@ namespace SixLabors.ImageSharp.Dithering while (length > bayerLength); // Create our Bayer matrix that matches the given exponent and dimensions - var matrix = new Fast2DArray((int)length); + var matrix = new DenseMatrix((int)length); uint i = 0; for (int y = 0; y < length; y++) { @@ -81,9 +81,9 @@ namespace SixLabors.ImageSharp.Dithering uint result = 0; for (uint i = 0; i < order; ++i) { - uint xOdd_XOR_yOdd = (x & 1) ^ (y & 1); + uint xOddXorYOdd = (x & 1) ^ (y & 1); uint xOdd = x & 1; - result = ((result << 1 | xOdd_XOR_yOdd) << 1) | xOdd; + result = ((result << 1 | xOddXorYOdd) << 1) | xOdd; x >>= 1; y >>= 1; } diff --git a/src/ImageSharp/Processing/Processors/Dithering/ErrorDiffusionPaletteProcessor.cs b/src/ImageSharp/Processing/Dithering/Processors/ErrorDiffusionPaletteProcessor.cs similarity index 93% rename from src/ImageSharp/Processing/Processors/Dithering/ErrorDiffusionPaletteProcessor.cs rename to src/ImageSharp/Processing/Dithering/Processors/ErrorDiffusionPaletteProcessor.cs index 152959cb73..c90e91a6b6 100644 --- a/src/ImageSharp/Processing/Processors/Dithering/ErrorDiffusionPaletteProcessor.cs +++ b/src/ImageSharp/Processing/Dithering/Processors/ErrorDiffusionPaletteProcessor.cs @@ -3,12 +3,12 @@ using System; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Dithering; -using SixLabors.ImageSharp.Helpers; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion; +using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Dithering.Processors { /// /// An that dithers an image using error diffusion. @@ -63,7 +63,7 @@ namespace SixLabors.ImageSharp.Processing.Processors public float Threshold { get; } /// - protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) + protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { float threshold = this.Threshold * 255F; var rgba = default(Rgba32); diff --git a/src/ImageSharp/Processing/Processors/Dithering/OrderedDitherPaletteProcessor.cs b/src/ImageSharp/Processing/Dithering/Processors/OrderedDitherPaletteProcessor.cs similarity index 92% rename from src/ImageSharp/Processing/Processors/Dithering/OrderedDitherPaletteProcessor.cs rename to src/ImageSharp/Processing/Dithering/Processors/OrderedDitherPaletteProcessor.cs index 4fc59585a9..ce9b7fb3ea 100644 --- a/src/ImageSharp/Processing/Processors/Dithering/OrderedDitherPaletteProcessor.cs +++ b/src/ImageSharp/Processing/Dithering/Processors/OrderedDitherPaletteProcessor.cs @@ -3,12 +3,12 @@ using System; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Dithering; -using SixLabors.ImageSharp.Helpers; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Dithering.Ordered; +using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Dithering.Processors { /// /// An that dithers an image using error diffusion. @@ -45,7 +45,7 @@ namespace SixLabors.ImageSharp.Processing.Processors public IOrderedDither Dither { get; } /// - protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) + protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { var rgba = default(Rgba32); bool isAlphaOnly = typeof(TPixel) == typeof(Alpha8); diff --git a/src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessorBase.cs b/src/ImageSharp/Processing/Dithering/Processors/PaletteDitherProcessorBase.cs similarity index 93% rename from src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessorBase.cs rename to src/ImageSharp/Processing/Dithering/Processors/PaletteDitherProcessorBase.cs index 4e6b7bec0e..89cc7cfb64 100644 --- a/src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessorBase.cs +++ b/src/ImageSharp/Processing/Dithering/Processors/PaletteDitherProcessorBase.cs @@ -5,8 +5,9 @@ using System.Collections.Generic; using System.Numerics; using System.Runtime.CompilerServices; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Dithering.Processors { /// /// The base class for dither and diffusion processors that consume a palette. @@ -20,7 +21,7 @@ namespace SixLabors.ImageSharp.Processing.Processors /// Initializes a new instance of the class. /// /// The palette to select substitute colors from. - public PaletteDitherProcessorBase(TPixel[] palette) + protected PaletteDitherProcessorBase(TPixel[] palette) { Guard.NotNull(palette, nameof(palette)); this.Palette = palette; diff --git a/src/ImageSharp/Processing/Processors/Dithering/PixelPair.cs b/src/ImageSharp/Processing/Dithering/Processors/PixelPair.cs similarity index 96% rename from src/ImageSharp/Processing/Processors/Dithering/PixelPair.cs rename to src/ImageSharp/Processing/Dithering/Processors/PixelPair.cs index 07045bb5ab..127c0be6d0 100644 --- a/src/ImageSharp/Processing/Processors/Dithering/PixelPair.cs +++ b/src/ImageSharp/Processing/Dithering/Processors/PixelPair.cs @@ -4,7 +4,7 @@ using System; using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Dithering.Processors { /// /// Represents a composite pair of pixels. Used for caching color distance lookups. diff --git a/src/ImageSharp/Dithering/error_diffusion.txt b/src/ImageSharp/Processing/Dithering/error_diffusion.txt similarity index 100% rename from src/ImageSharp/Dithering/error_diffusion.txt rename to src/ImageSharp/Processing/Dithering/error_diffusion.txt diff --git a/src/ImageSharp/Processing/Effects/OilPainting.cs b/src/ImageSharp/Processing/Effects/OilPaintExtensions.cs similarity index 86% rename from src/ImageSharp/Processing/Effects/OilPainting.cs rename to src/ImageSharp/Processing/Effects/OilPaintExtensions.cs index 0494c9a8b9..a04bbec4e5 100644 --- a/src/ImageSharp/Processing/Effects/OilPainting.cs +++ b/src/ImageSharp/Processing/Effects/OilPaintExtensions.cs @@ -1,17 +1,16 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Effects.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Effects { /// - /// Extension methods for the type. + /// Adds oil painting effect extensions to the type. /// - public static partial class ImageExtensions + public static class OilPaintExtensions { /// /// Alters the colors of the image recreating an oil painting effect with levels and brushSize @@ -22,9 +21,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext OilPaint(this IImageProcessingContext source) where TPixel : struct, IPixel - { - return OilPaint(source, 10, 15); - } + => OilPaint(source, 10, 15); /// /// Alters the colors of the image recreating an oil painting effect with levels and brushSize @@ -38,9 +35,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext OilPaint(this IImageProcessingContext source, Rectangle rectangle) where TPixel : struct, IPixel - { - return OilPaint(source, 10, 15, rectangle); - } + => OilPaint(source, 10, 15, rectangle); /// /// Alters the colors of the image recreating an oil painting effect. @@ -52,7 +47,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext OilPaint(this IImageProcessingContext source, int levels, int brushSize) where TPixel : struct, IPixel - => source.ApplyProcessor(new OilPaintingProcessor(levels, brushSize)); + => source.ApplyProcessor(new OilPaintingProcessor(levels, brushSize)); /// /// Alters the colors of the image recreating an oil painting effect. @@ -67,6 +62,6 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext OilPaint(this IImageProcessingContext source, int levels, int brushSize, Rectangle rectangle) where TPixel : struct, IPixel - => source.ApplyProcessor(new OilPaintingProcessor(levels, brushSize), rectangle); + => source.ApplyProcessor(new OilPaintingProcessor(levels, brushSize), rectangle); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Effects/Pixelate.cs b/src/ImageSharp/Processing/Effects/PixelateExtensions.cs similarity index 81% rename from src/ImageSharp/Processing/Effects/Pixelate.cs rename to src/ImageSharp/Processing/Effects/PixelateExtensions.cs index 29e348f6e6..d6fcfe6f15 100644 --- a/src/ImageSharp/Processing/Effects/Pixelate.cs +++ b/src/ImageSharp/Processing/Effects/PixelateExtensions.cs @@ -1,17 +1,16 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Effects.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Effects { /// - /// Extension methods for the type. + /// Adds pixelation effect extensions to the type. /// - public static partial class ImageExtensions + public static class PixelateExtensions { /// /// Pixelates an image with the given pixel size. @@ -21,7 +20,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Pixelate(this IImageProcessingContext source) where TPixel : struct, IPixel - => source.ApplyProcessor(new PixelateProcessor(4)); + => Pixelate(source, 4); /// /// Pixelates an image with the given pixel size. @@ -32,7 +31,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Pixelate(this IImageProcessingContext source, int size) where TPixel : struct, IPixel - => source.ApplyProcessor(new PixelateProcessor(size)); + => source.ApplyProcessor(new PixelateProcessor(size)); /// /// Pixelates an image with the given pixel size. @@ -46,6 +45,6 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Pixelate(this IImageProcessingContext source, int size, Rectangle rectangle) where TPixel : struct, IPixel - => source.ApplyProcessor(new PixelateProcessor(size), rectangle); + => source.ApplyProcessor(new PixelateProcessor(size), rectangle); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs b/src/ImageSharp/Processing/Effects/Processors/OilPaintingProcessor.cs similarity index 94% rename from src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs rename to src/ImageSharp/Processing/Effects/Processors/OilPaintingProcessor.cs index c199a32c8a..9a6d93d1a3 100644 --- a/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs +++ b/src/ImageSharp/Processing/Effects/Processors/OilPaintingProcessor.cs @@ -5,15 +5,15 @@ using System; using System.Numerics; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Helpers; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Effects.Processors { /// - /// An to apply an oil painting effect to an . + /// Applies oil painting effect processing to the image. /// /// Adapted from by Dewald Esterhuizen. /// The pixel format. @@ -49,7 +49,7 @@ namespace SixLabors.ImageSharp.Processing.Processors public int BrushSize { get; } /// - protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) + protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { if (this.BrushSize <= 0 || this.BrushSize > source.Height || this.BrushSize > source.Width) { diff --git a/src/ImageSharp/Processing/Processors/Effects/PixelateProcessor.cs b/src/ImageSharp/Processing/Effects/Processors/PixelateProcessor.cs similarity index 92% rename from src/ImageSharp/Processing/Processors/Effects/PixelateProcessor.cs rename to src/ImageSharp/Processing/Effects/Processors/PixelateProcessor.cs index 0ab21f65ac..d45d2093fb 100644 --- a/src/ImageSharp/Processing/Processors/Effects/PixelateProcessor.cs +++ b/src/ImageSharp/Processing/Effects/Processors/PixelateProcessor.cs @@ -7,12 +7,13 @@ using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Common; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Effects.Processors { /// - /// An to pixelate the colors of an . + /// Applies a pixelation effect processing to the image. /// /// The pixel format. internal class PixelateProcessor : ImageProcessor @@ -37,7 +38,7 @@ namespace SixLabors.ImageSharp.Processing.Processors public int Size { get; } /// - protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) + protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { if (this.Size <= 0 || this.Size > source.Height || this.Size > source.Width) { diff --git a/src/ImageSharp/Processing/ColorMatrix/BlackWhite.cs b/src/ImageSharp/Processing/Filters/BlackWhiteExtensions.cs similarity index 75% rename from src/ImageSharp/Processing/ColorMatrix/BlackWhite.cs rename to src/ImageSharp/Processing/Filters/BlackWhiteExtensions.cs index d64db34bad..f30cefb860 100644 --- a/src/ImageSharp/Processing/ColorMatrix/BlackWhite.cs +++ b/src/ImageSharp/Processing/Filters/BlackWhiteExtensions.cs @@ -2,15 +2,15 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Filters.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Filters { /// - /// Extension methods for the type. + /// Adds extensions that allow the application of black and white toning to the type. /// - public static partial class ImageExtensions + public static class BlackWhiteExtensions { /// /// Applies black and white toning to the image. @@ -20,10 +20,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext BlackWhite(this IImageProcessingContext source) where TPixel : struct, IPixel - { - source.ApplyProcessor(new BlackWhiteProcessor()); - return source; - } + => source.ApplyProcessor(new BlackWhiteProcessor()); /// /// Applies black and white toning to the image. @@ -36,9 +33,6 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext BlackWhite(this IImageProcessingContext source, Rectangle rectangle) where TPixel : struct, IPixel - { - source.ApplyProcessor(new BlackWhiteProcessor(), rectangle); - return source; - } + => source.ApplyProcessor(new BlackWhiteProcessor(), rectangle); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/ColorMatrix/Brightness.cs b/src/ImageSharp/Processing/Filters/BrightnessExtensions.cs similarity index 83% rename from src/ImageSharp/Processing/ColorMatrix/Brightness.cs rename to src/ImageSharp/Processing/Filters/BrightnessExtensions.cs index 34b5347841..a36d588d5d 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Brightness.cs +++ b/src/ImageSharp/Processing/Filters/BrightnessExtensions.cs @@ -1,17 +1,16 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Filters.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Filters { /// - /// Extension methods for the type. + /// Adds extensions that allow the alteration of the brightness component to the type. /// - public static partial class ImageExtensions + public static class BrightnessExtensions { /// /// Alters the brightness component of the image. @@ -26,7 +25,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Brightness(this IImageProcessingContext source, float amount) where TPixel : struct, IPixel - => source.ApplyProcessor(new BrightnessProcessor(amount)); + => source.ApplyProcessor(new BrightnessProcessor(amount)); /// /// Alters the brightness component of the image. @@ -44,6 +43,6 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Brightness(this IImageProcessingContext source, float amount, Rectangle rectangle) where TPixel : struct, IPixel - => source.ApplyProcessor(new BrightnessProcessor(amount), rectangle); + => source.ApplyProcessor(new BrightnessProcessor(amount), rectangle); } } diff --git a/src/ImageSharp/Processing/ColorMatrix/Options/ColorBlindness.cs b/src/ImageSharp/Processing/Filters/ColorBlindness.cs similarity index 95% rename from src/ImageSharp/Processing/ColorMatrix/Options/ColorBlindness.cs rename to src/ImageSharp/Processing/Filters/ColorBlindness.cs index 1b92029f6b..41d468f340 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Options/ColorBlindness.cs +++ b/src/ImageSharp/Processing/Filters/ColorBlindness.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing.Filters { /// /// Enumerates the various types of defined color blindness filters. diff --git a/src/ImageSharp/Processing/ColorMatrix/ColorBlindness.cs b/src/ImageSharp/Processing/Filters/ColorBlindnessExtensions.cs similarity index 72% rename from src/ImageSharp/Processing/ColorMatrix/ColorBlindness.cs rename to src/ImageSharp/Processing/Filters/ColorBlindnessExtensions.cs index ebfa9ffdcd..b7dc871503 100644 --- a/src/ImageSharp/Processing/ColorMatrix/ColorBlindness.cs +++ b/src/ImageSharp/Processing/Filters/ColorBlindnessExtensions.cs @@ -1,18 +1,17 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Filters.Processors; using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Filters { /// - /// Extension methods for the type. + /// Adds extensions that simulate the effects of various color blindness disorders to the type. /// - public static partial class ImageExtensions + public static class ColorBlindnessExtensions { /// /// Applies the given colorblindness simulator to the image. @@ -23,10 +22,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext ColorBlindness(this IImageProcessingContext source, ColorBlindness colorBlindness) where TPixel : struct, IPixel - { - source.ApplyProcessor(GetProcessor(colorBlindness)); - return source; - } + => source.ApplyProcessor(GetProcessor(colorBlindness)); /// /// Applies the given colorblindness simulator to the image. @@ -40,33 +36,30 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext ColorBlindness(this IImageProcessingContext source, ColorBlindness colorBlindness, Rectangle rectangle) where TPixel : struct, IPixel - { - source.ApplyProcessor(GetProcessor(colorBlindness), rectangle); - return source; - } + => source.ApplyProcessor(GetProcessor(colorBlindness), rectangle); private static IImageProcessor GetProcessor(ColorBlindness colorBlindness) where TPixel : struct, IPixel { switch (colorBlindness) { - case ImageSharp.Processing.ColorBlindness.Achromatomaly: + case Filters.ColorBlindness.Achromatomaly: return new AchromatomalyProcessor(); - case ImageSharp.Processing.ColorBlindness.Achromatopsia: + case Filters.ColorBlindness.Achromatopsia: return new AchromatopsiaProcessor(); - case ImageSharp.Processing.ColorBlindness.Deuteranomaly: + case Filters.ColorBlindness.Deuteranomaly: return new DeuteranomalyProcessor(); - case ImageSharp.Processing.ColorBlindness.Deuteranopia: + case Filters.ColorBlindness.Deuteranopia: return new DeuteranopiaProcessor(); - case ImageSharp.Processing.ColorBlindness.Protanomaly: + case Filters.ColorBlindness.Protanomaly: return new ProtanomalyProcessor(); - case ImageSharp.Processing.ColorBlindness.Protanopia: + case Filters.ColorBlindness.Protanopia: return new ProtanopiaProcessor(); - case ImageSharp.Processing.ColorBlindness.Tritanomaly: + case Filters.ColorBlindness.Tritanomaly: return new TritanomalyProcessor(); default: return new TritanopiaProcessor(); } } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/ColorMatrix/Contrast.cs b/src/ImageSharp/Processing/Filters/ContrastExtensions.cs similarity index 83% rename from src/ImageSharp/Processing/ColorMatrix/Contrast.cs rename to src/ImageSharp/Processing/Filters/ContrastExtensions.cs index e0f388e287..16225039c3 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Contrast.cs +++ b/src/ImageSharp/Processing/Filters/ContrastExtensions.cs @@ -2,15 +2,15 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Filters.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Filters { /// - /// Extension methods for the type. + /// Adds extensions that allow the alteration of the contrast component to the type. /// - public static partial class ImageExtensions + public static class ContrastExtensions { /// /// Alters the contrast component of the image. @@ -25,7 +25,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Contrast(this IImageProcessingContext source, float amount) where TPixel : struct, IPixel - => source.ApplyProcessor(new ContrastProcessor(amount)); + => source.ApplyProcessor(new ContrastProcessor(amount)); /// /// Alters the contrast component of the image. @@ -43,6 +43,6 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Contrast(this IImageProcessingContext source, float amount, Rectangle rectangle) where TPixel : struct, IPixel - => source.ApplyProcessor(new ContrastProcessor(amount), rectangle); + => source.ApplyProcessor(new ContrastProcessor(amount), rectangle); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/ColorMatrix/Filter.cs b/src/ImageSharp/Processing/Filters/FilterExtensions.cs similarity index 77% rename from src/ImageSharp/Processing/ColorMatrix/Filter.cs rename to src/ImageSharp/Processing/Filters/FilterExtensions.cs index 7eb684978a..ae8bbda030 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Filter.cs +++ b/src/ImageSharp/Processing/Filters/FilterExtensions.cs @@ -3,15 +3,15 @@ using System.Numerics; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Filters.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Filters { /// - /// Extension methods for the type. + /// Adds extensions that allow the application of composable filters to the type. /// - public static partial class ImageExtensions + public static class FilterExtensions { /// /// Filters an image but the given color matrix @@ -22,10 +22,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Filter(this IImageProcessingContext source, Matrix4x4 matrix) where TPixel : struct, IPixel - { - source.ApplyProcessor(new FilterProcessor(matrix)); - return source; - } + => source.ApplyProcessor(new FilterProcessor(matrix)); /// /// Filters an image but the given color matrix @@ -39,9 +36,6 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Filter(this IImageProcessingContext source, Matrix4x4 matrix, Rectangle rectangle) where TPixel : struct, IPixel - { - source.ApplyProcessor(new FilterProcessor(matrix), rectangle); - return source; - } + => source.ApplyProcessor(new FilterProcessor(matrix), rectangle); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/ColorMatrix/Grayscale.cs b/src/ImageSharp/Processing/Filters/GrayscaleExtensions.cs similarity index 86% rename from src/ImageSharp/Processing/ColorMatrix/Grayscale.cs rename to src/ImageSharp/Processing/Filters/GrayscaleExtensions.cs index ee43d5b016..34ee4d0f37 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Grayscale.cs +++ b/src/ImageSharp/Processing/Filters/GrayscaleExtensions.cs @@ -2,29 +2,29 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Filters.Processors; using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Filters { /// - /// Extension methods for the type. + /// Adds extensions that allow the application of grayscale toning to the type. /// - public static partial class ImageExtensions + public static class GrayscaleExtensions { /// - /// Applies Grayscale toning to the image. + /// Applies grayscale toning to the image. /// /// The pixel format. /// The image this method extends. /// The . public static IImageProcessingContext Grayscale(this IImageProcessingContext source) where TPixel : struct, IPixel - => Grayscale(source, GrayscaleMode.Bt709); + => Grayscale(source, GrayscaleMode.Bt709); /// - /// Applies Grayscale toning to the image using the given amount. + /// Applies grayscale toning to the image using the given amount. /// /// The pixel format. /// The image this method extends. @@ -32,7 +32,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Grayscale(this IImageProcessingContext source, float amount) where TPixel : struct, IPixel - => Grayscale(source, GrayscaleMode.Bt709, amount); + => Grayscale(source, GrayscaleMode.Bt709, amount); /// /// Applies grayscale toning to the image with the given . @@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Grayscale(this IImageProcessingContext source, GrayscaleMode mode) where TPixel : struct, IPixel - => Grayscale(source, mode, 1F); + => Grayscale(source, mode, 1F); /// /// Applies grayscale toning to the image with the given using the given amount. @@ -65,7 +65,7 @@ namespace SixLabors.ImageSharp } /// - /// Applies Grayscale toning to the image. + /// Applies grayscale toning to the image. /// /// The pixel format. /// The image this method extends. @@ -75,10 +75,10 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Grayscale(this IImageProcessingContext source, Rectangle rectangle) where TPixel : struct, IPixel - => Grayscale(source, 1F, rectangle); + => Grayscale(source, 1F, rectangle); /// - /// Applies Grayscale toning to the image using the given amount. + /// Applies grayscale toning to the image using the given amount. /// /// The pixel format. /// The image this method extends. @@ -89,10 +89,10 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Grayscale(this IImageProcessingContext source, float amount, Rectangle rectangle) where TPixel : struct, IPixel - => Grayscale(source, GrayscaleMode.Bt709, amount, rectangle); + => Grayscale(source, GrayscaleMode.Bt709, amount, rectangle); /// - /// Applies Grayscale toning to the image. + /// Applies grayscale toning to the image. /// /// The pixel format. /// The image this method extends. @@ -103,10 +103,10 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Grayscale(this IImageProcessingContext source, GrayscaleMode mode, Rectangle rectangle) where TPixel : struct, IPixel - => Grayscale(source, mode, 1F, rectangle); + => Grayscale(source, mode, 1F, rectangle); /// - /// Applies Grayscale toning to the image using the given amount. + /// Applies grayscale toning to the image using the given amount. /// /// The pixel format. /// The image this method extends. diff --git a/src/ImageSharp/Processing/ColorMatrix/Options/GrayscaleMode.cs b/src/ImageSharp/Processing/Filters/GrayscaleMode.cs similarity index 77% rename from src/ImageSharp/Processing/ColorMatrix/Options/GrayscaleMode.cs rename to src/ImageSharp/Processing/Filters/GrayscaleMode.cs index 370071b7ab..db30e67ff4 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Options/GrayscaleMode.cs +++ b/src/ImageSharp/Processing/Filters/GrayscaleMode.cs @@ -1,10 +1,10 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing.Filters { /// - /// Enumerates the various types of defined Grayscale filters. + /// Enumerates the various types of defined grayscale filters. /// public enum GrayscaleMode { @@ -18,4 +18,4 @@ namespace SixLabors.ImageSharp.Processing /// Bt601 } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/ColorMatrix/Hue.cs b/src/ImageSharp/Processing/Filters/HueExtensions.cs similarity index 75% rename from src/ImageSharp/Processing/ColorMatrix/Hue.cs rename to src/ImageSharp/Processing/Filters/HueExtensions.cs index 76af10c369..1b730d7f02 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Hue.cs +++ b/src/ImageSharp/Processing/Filters/HueExtensions.cs @@ -1,18 +1,16 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Filters.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Filters { /// - /// Extension methods for the type. + /// Adds extensions that allow the alteration of the hue component to the type. /// - public static partial class ImageExtensions + public static class HueExtensions { /// /// Alters the hue component of the image. @@ -23,10 +21,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Hue(this IImageProcessingContext source, float degrees) where TPixel : struct, IPixel - { - source.ApplyProcessor(new HueProcessor(degrees)); - return source; - } + => source.ApplyProcessor(new HueProcessor(degrees)); /// /// Alters the hue component of the image. @@ -40,9 +35,6 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Hue(this IImageProcessingContext source, float degrees, Rectangle rectangle) where TPixel : struct, IPixel - { - source.ApplyProcessor(new HueProcessor(degrees), rectangle); - return source; - } + => source.ApplyProcessor(new HueProcessor(degrees), rectangle); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Effects/Invert.cs b/src/ImageSharp/Processing/Filters/InvertExtensions.cs similarity index 76% rename from src/ImageSharp/Processing/Effects/Invert.cs rename to src/ImageSharp/Processing/Filters/InvertExtensions.cs index 7dd9ed3dd7..784b37c56e 100644 --- a/src/ImageSharp/Processing/Effects/Invert.cs +++ b/src/ImageSharp/Processing/Filters/InvertExtensions.cs @@ -1,17 +1,16 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Filters.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Filters { /// - /// Extension methods for the type. + /// Adds extensions that allow the inversion of colors to the type. /// - public static partial class ImageExtensions + public static class InvertExtensions { /// /// Inverts the colors of the image. @@ -21,7 +20,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Invert(this IImageProcessingContext source) where TPixel : struct, IPixel - => source.ApplyProcessor(new InvertProcessor(1F)); + => source.ApplyProcessor(new InvertProcessor(1F)); /// /// Inverts the colors of the image. @@ -34,6 +33,6 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Invert(this IImageProcessingContext source, Rectangle rectangle) where TPixel : struct, IPixel - => source.ApplyProcessor(new InvertProcessor(1F), rectangle); + => source.ApplyProcessor(new InvertProcessor(1F), rectangle); } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/ColorMatrix/Kodachrome.cs b/src/ImageSharp/Processing/Filters/KodachromeExtensions.cs similarity index 74% rename from src/ImageSharp/Processing/ColorMatrix/Kodachrome.cs rename to src/ImageSharp/Processing/Filters/KodachromeExtensions.cs index d7845320ad..94f1acc0c0 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Kodachrome.cs +++ b/src/ImageSharp/Processing/Filters/KodachromeExtensions.cs @@ -1,18 +1,16 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Filters.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Filters { /// - /// Extension methods for the type. + /// Adds extensions that allow the recreation of an old Kodachrome camera effect to the type. /// - public static partial class ImageExtensions + public static class KodachromeExtensions { /// /// Alters the colors of the image recreating an old Kodachrome camera effect. @@ -22,10 +20,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Kodachrome(this IImageProcessingContext source) where TPixel : struct, IPixel - { - source.ApplyProcessor(new KodachromeProcessor()); - return source; - } + => source.ApplyProcessor(new KodachromeProcessor()); /// /// Alters the colors of the image recreating an old Kodachrome camera effect. @@ -38,9 +33,6 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Kodachrome(this IImageProcessingContext source, Rectangle rectangle) where TPixel : struct, IPixel - { - source.ApplyProcessor(new KodachromeProcessor(), rectangle); - return source; - } + => source.ApplyProcessor(new KodachromeProcessor(), rectangle); } } diff --git a/src/ImageSharp/Processing/Filters/LomographExtensions.cs b/src/ImageSharp/Processing/Filters/LomographExtensions.cs new file mode 100644 index 0000000000..ed9e1cc297 --- /dev/null +++ b/src/ImageSharp/Processing/Filters/LomographExtensions.cs @@ -0,0 +1,38 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Filters.Processors; +using SixLabors.Primitives; + +namespace SixLabors.ImageSharp.Processing.Filters +{ + /// + /// Adds extensions that allow the recreation of an old Lomograph camera effect to the type. + /// + public static class LomographExtensions + { + /// + /// Alters the colors of the image recreating an old Lomograph camera effect. + /// + /// The pixel format. + /// The image this method extends. + /// The . + public static IImageProcessingContext Lomograph(this IImageProcessingContext source) + where TPixel : struct, IPixel + => source.ApplyProcessor(new LomographProcessor()); + + /// + /// Alters the colors of the image recreating an old Lomograph camera effect. + /// + /// The pixel format. + /// The image this method extends. + /// + /// The structure that specifies the portion of the image object to alter. + /// + /// The . + public static IImageProcessingContext Lomograph(this IImageProcessingContext source, Rectangle rectangle) + where TPixel : struct, IPixel + => source.ApplyProcessor(new LomographProcessor(), rectangle); + } +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/ColorMatrix/MatrixFilters.cs b/src/ImageSharp/Processing/Filters/MatrixFilters.cs similarity index 98% rename from src/ImageSharp/Processing/ColorMatrix/MatrixFilters.cs rename to src/ImageSharp/Processing/Filters/MatrixFilters.cs index 8cbc21b2a6..2f5883fc9c 100644 --- a/src/ImageSharp/Processing/ColorMatrix/MatrixFilters.cs +++ b/src/ImageSharp/Processing/Filters/MatrixFilters.cs @@ -4,10 +4,10 @@ using System; using System.Numerics; -namespace SixLabors.ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing.Filters { /// - /// Provides extensions methods for the struct + /// A collection of known values for composing filters /// public static class MatrixFilters { @@ -253,7 +253,7 @@ namespace SixLabors.ImageSharp.Processing } /// - /// Create a greyscale filter matrix using the given amount using the formula as specified by ITU-R Recommendation BT.601. + /// Create a grayscale filter matrix using the given amount using the formula as specified by ITU-R Recommendation BT.601. /// /// /// The proportion of the conversion. Must be between 0 and 1. @@ -280,7 +280,7 @@ namespace SixLabors.ImageSharp.Processing } /// - /// Create a greyscale filter matrix using the given amount using the formula as specified by ITU-R Recommendation BT.709. + /// Create a grayscale filter matrix using the given amount using the formula as specified by ITU-R Recommendation BT.709. /// /// /// The proportion of the conversion. Must be between 0 and 1. diff --git a/src/ImageSharp/Processing/ColorMatrix/Opacity.cs b/src/ImageSharp/Processing/Filters/OpacityExtensions.cs similarity index 78% rename from src/ImageSharp/Processing/ColorMatrix/Opacity.cs rename to src/ImageSharp/Processing/Filters/OpacityExtensions.cs index b59c068905..e263fef4ee 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Opacity.cs +++ b/src/ImageSharp/Processing/Filters/OpacityExtensions.cs @@ -1,17 +1,16 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Filters.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Filters { /// - /// Extension methods for the type. + /// Adds extensions that allow the alteration of the opacity component to the type. /// - public static partial class ImageExtensions + public static class OpacityExtensions { /// /// Multiplies the alpha component of the image. @@ -22,7 +21,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Opacity(this IImageProcessingContext source, float amount) where TPixel : struct, IPixel - => source.ApplyProcessor(new OpacityProcessor(amount)); + => source.ApplyProcessor(new OpacityProcessor(amount)); /// /// Multiplies the alpha component of the image. @@ -36,6 +35,6 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Opacity(this IImageProcessingContext source, float amount, Rectangle rectangle) where TPixel : struct, IPixel - => source.ApplyProcessor(new OpacityProcessor(amount), rectangle); + => source.ApplyProcessor(new OpacityProcessor(amount), rectangle); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Filters/PolaroidExtensions.cs b/src/ImageSharp/Processing/Filters/PolaroidExtensions.cs new file mode 100644 index 0000000000..37f06f9cf0 --- /dev/null +++ b/src/ImageSharp/Processing/Filters/PolaroidExtensions.cs @@ -0,0 +1,38 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Filters.Processors; +using SixLabors.Primitives; + +namespace SixLabors.ImageSharp.Processing.Filters +{ + /// + /// Adds extensions that allow the recreation of an old Polaroid camera effect to the type. + /// + public static class PolaroidExtensions + { + /// + /// Alters the colors of the image recreating an old Polaroid camera effect. + /// + /// The pixel format. + /// The image this method extends. + /// The . + public static IImageProcessingContext Polaroid(this IImageProcessingContext source) + where TPixel : struct, IPixel + => source.ApplyProcessor(new PolaroidProcessor()); + + /// + /// Alters the colors of the image recreating an old Polaroid camera effect. + /// + /// The pixel format. + /// The image this method extends. + /// + /// The structure that specifies the portion of the image object to alter. + /// + /// The . + public static IImageProcessingContext Polaroid(this IImageProcessingContext source, Rectangle rectangle) + where TPixel : struct, IPixel + => source.ApplyProcessor(new PolaroidProcessor(), rectangle); + } +} diff --git a/src/ImageSharp/Processing/Processors/Filters/ColorBlindness/AchromatomalyProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/AchromatomalyProcessor.cs similarity index 92% rename from src/ImageSharp/Processing/Processors/Filters/ColorBlindness/AchromatomalyProcessor.cs rename to src/ImageSharp/Processing/Filters/Processors/AchromatomalyProcessor.cs index 8d9bf98579..55c6220308 100644 --- a/src/ImageSharp/Processing/Processors/Filters/ColorBlindness/AchromatomalyProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/AchromatomalyProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Filters.Processors { /// /// Converts the colors of the image recreating Achromatomaly (Color desensitivity) color blindness. diff --git a/src/ImageSharp/Processing/Processors/Filters/ColorBlindness/AchromatopsiaProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/AchromatopsiaProcessor.cs similarity index 92% rename from src/ImageSharp/Processing/Processors/Filters/ColorBlindness/AchromatopsiaProcessor.cs rename to src/ImageSharp/Processing/Filters/Processors/AchromatopsiaProcessor.cs index f19c55933d..95f9e893be 100644 --- a/src/ImageSharp/Processing/Processors/Filters/ColorBlindness/AchromatopsiaProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/AchromatopsiaProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Filters.Processors { /// /// Converts the colors of the image recreating Achromatopsia (Monochrome) color blindness. diff --git a/src/ImageSharp/Processing/Processors/Filters/BlackWhiteProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/BlackWhiteProcessor.cs similarity index 91% rename from src/ImageSharp/Processing/Processors/Filters/BlackWhiteProcessor.cs rename to src/ImageSharp/Processing/Filters/Processors/BlackWhiteProcessor.cs index 30fcfab4fd..f6a420257e 100644 --- a/src/ImageSharp/Processing/Processors/Filters/BlackWhiteProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/BlackWhiteProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Filters.Processors { /// /// Applies a black and white filter matrix to the image diff --git a/src/ImageSharp/Processing/Processors/Filters/BrightnessProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/BrightnessProcessor.cs similarity index 85% rename from src/ImageSharp/Processing/Processors/Filters/BrightnessProcessor.cs rename to src/ImageSharp/Processing/Filters/Processors/BrightnessProcessor.cs index b1a68a9c91..c6f758634d 100644 --- a/src/ImageSharp/Processing/Processors/Filters/BrightnessProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/BrightnessProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Filters.Processors { /// /// Applies a brightness filter matrix using the given amount. @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Processing.Processors /// Initializes a new instance of the class. /// /// - /// A value of 0 will create an image that is completely black. A value of 1 leaves the input unchanged. + /// A value of 0 will create an image that is completely black. A value of 1 leaves the input unchanged. /// Other values are linear multipliers on the effect. Values of an amount over 1 are allowed, providing brighter results. /// /// The proportion of the conversion. Must be greater than or equal to 0. diff --git a/src/ImageSharp/Processing/Processors/Filters/ContrastProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/ContrastProcessor.cs similarity index 85% rename from src/ImageSharp/Processing/Processors/Filters/ContrastProcessor.cs rename to src/ImageSharp/Processing/Filters/Processors/ContrastProcessor.cs index 8ebeb939fb..3a8022703c 100644 --- a/src/ImageSharp/Processing/Processors/Filters/ContrastProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/ContrastProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Filters.Processors { /// /// Applies a contrast filter matrix using the given amount. @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Processing.Processors /// Initializes a new instance of the class. /// /// - /// A value of 0 will create an image that is completely gray. A value of 1 leaves the input unchanged. + /// A value of 0 will create an image that is completely gray. A value of 1 leaves the input unchanged. /// Other values are linear multipliers on the effect. Values of an amount over 1 are allowed, providing results with more contrast. /// /// The proportion of the conversion. Must be greater than or equal to 0. diff --git a/src/ImageSharp/Processing/Processors/Filters/ColorBlindness/DeuteranomalyProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/DeuteranomalyProcessor.cs similarity index 92% rename from src/ImageSharp/Processing/Processors/Filters/ColorBlindness/DeuteranomalyProcessor.cs rename to src/ImageSharp/Processing/Filters/Processors/DeuteranomalyProcessor.cs index 20a1d4ab46..31ea79afe2 100644 --- a/src/ImageSharp/Processing/Processors/Filters/ColorBlindness/DeuteranomalyProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/DeuteranomalyProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Filters.Processors { /// /// Converts the colors of the image recreating Deuteranomaly (Green-Weak) color blindness. diff --git a/src/ImageSharp/Processing/Processors/Filters/ColorBlindness/DeuteranopiaProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/DeuteranopiaProcessor.cs similarity index 92% rename from src/ImageSharp/Processing/Processors/Filters/ColorBlindness/DeuteranopiaProcessor.cs rename to src/ImageSharp/Processing/Filters/Processors/DeuteranopiaProcessor.cs index e5e0225718..5ed7e85408 100644 --- a/src/ImageSharp/Processing/Processors/Filters/ColorBlindness/DeuteranopiaProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/DeuteranopiaProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Filters.Processors { /// /// Converts the colors of the image recreating Deuteranopia (Green-Blind) color blindness. diff --git a/src/ImageSharp/Processing/Processors/Filters/FilterProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/FilterProcessor.cs similarity index 87% rename from src/ImageSharp/Processing/Processors/Filters/FilterProcessor.cs rename to src/ImageSharp/Processing/Filters/Processors/FilterProcessor.cs index 30fe8c6b6f..18163b7548 100644 --- a/src/ImageSharp/Processing/Processors/Filters/FilterProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/FilterProcessor.cs @@ -5,14 +5,14 @@ using System; using System.Numerics; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Helpers; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Filters.Processors { /// - /// Provides methods that accept a matrix to apply freeform filters to images. + /// Provides methods that accept a matrix to apply free-form filters to images. /// /// The pixel format. internal class FilterProcessor : ImageProcessor @@ -33,7 +33,7 @@ namespace SixLabors.ImageSharp.Processing.Processors public Matrix4x4 Matrix { get; } /// - protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) + protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { var interest = Rectangle.Intersect(sourceRectangle, source.Bounds()); int startY = interest.Y; diff --git a/src/ImageSharp/Processing/Processors/Filters/GrayscaleBt601Processor.cs b/src/ImageSharp/Processing/Filters/Processors/GrayscaleBt601Processor.cs similarity index 88% rename from src/ImageSharp/Processing/Processors/Filters/GrayscaleBt601Processor.cs rename to src/ImageSharp/Processing/Filters/Processors/GrayscaleBt601Processor.cs index 7ea52dcb92..fa483752c5 100644 --- a/src/ImageSharp/Processing/Processors/Filters/GrayscaleBt601Processor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/GrayscaleBt601Processor.cs @@ -3,10 +3,10 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Filters.Processors { /// - /// Applies a greyscale filter matrix using the given amount and the formula as specified by ITU-R Recommendation BT.601 + /// Applies a grayscale filter matrix using the given amount and the formula as specified by ITU-R Recommendation BT.601 /// /// The pixel format. internal class GrayscaleBt601Processor : FilterProcessor diff --git a/src/ImageSharp/Processing/Processors/Filters/GrayscaleBt709Processor.cs b/src/ImageSharp/Processing/Filters/Processors/GrayscaleBt709Processor.cs similarity index 94% rename from src/ImageSharp/Processing/Processors/Filters/GrayscaleBt709Processor.cs rename to src/ImageSharp/Processing/Filters/Processors/GrayscaleBt709Processor.cs index fcd7b2e8f5..396ad7d903 100644 --- a/src/ImageSharp/Processing/Processors/Filters/GrayscaleBt709Processor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/GrayscaleBt709Processor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Filters.Processors { /// /// Applies a grayscale filter matrix using the given amount and the formula as specified by ITU-R Recommendation BT.709 diff --git a/src/ImageSharp/Processing/Processors/Filters/HueProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/HueProcessor.cs similarity index 93% rename from src/ImageSharp/Processing/Processors/Filters/HueProcessor.cs rename to src/ImageSharp/Processing/Filters/Processors/HueProcessor.cs index 302314db40..31adf21259 100644 --- a/src/ImageSharp/Processing/Processors/Filters/HueProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/HueProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Filters.Processors { /// /// Applies a hue filter matrix using the given angle of rotation in degrees diff --git a/src/ImageSharp/Processing/Processors/Filters/InvertProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/InvertProcessor.cs similarity index 93% rename from src/ImageSharp/Processing/Processors/Filters/InvertProcessor.cs rename to src/ImageSharp/Processing/Filters/Processors/InvertProcessor.cs index e258e9d96e..e5175ca69b 100644 --- a/src/ImageSharp/Processing/Processors/Filters/InvertProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/InvertProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Filters.Processors { /// /// Applies a filter matrix that inverts the colors of an image diff --git a/src/ImageSharp/Processing/Processors/Filters/KodachromeProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/KodachromeProcessor.cs similarity index 92% rename from src/ImageSharp/Processing/Processors/Filters/KodachromeProcessor.cs rename to src/ImageSharp/Processing/Filters/Processors/KodachromeProcessor.cs index 6f27a04538..19f55507c4 100644 --- a/src/ImageSharp/Processing/Processors/Filters/KodachromeProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/KodachromeProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Filters.Processors { /// /// Applies a filter matrix recreating an old Kodachrome camera effect matrix to the image diff --git a/src/ImageSharp/Processing/Filters/Processors/LomographProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/LomographProcessor.cs new file mode 100644 index 0000000000..5e3d73fd19 --- /dev/null +++ b/src/ImageSharp/Processing/Filters/Processors/LomographProcessor.cs @@ -0,0 +1,33 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Overlays.Processors; +using SixLabors.Primitives; + +namespace SixLabors.ImageSharp.Processing.Filters.Processors +{ + /// + /// Converts the colors of the image recreating an old Lomograph effect. + /// + /// The pixel format. + internal class LomographProcessor : FilterProcessor + where TPixel : struct, IPixel + { + private static readonly TPixel VeryDarkGreen = ColorBuilder.FromRGBA(0, 10, 0, 255); + + /// + /// Initializes a new instance of the class. + /// + public LomographProcessor() + : base(MatrixFilters.LomographFilter) + { + } + + /// + protected override void AfterFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) + { + new VignetteProcessor(VeryDarkGreen).Apply(source, sourceRectangle, configuration); + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Processors/Filters/OpacityProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/OpacityProcessor.cs similarity index 93% rename from src/ImageSharp/Processing/Processors/Filters/OpacityProcessor.cs rename to src/ImageSharp/Processing/Filters/Processors/OpacityProcessor.cs index 1c0d2600ea..db9af9546c 100644 --- a/src/ImageSharp/Processing/Processors/Filters/OpacityProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/OpacityProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Filters.Processors { /// /// Applies an opacity filter matrix using the given amount. diff --git a/src/ImageSharp/Processing/Filters/Processors/PolaroidProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/PolaroidProcessor.cs new file mode 100644 index 0000000000..0e90efc7ec --- /dev/null +++ b/src/ImageSharp/Processing/Filters/Processors/PolaroidProcessor.cs @@ -0,0 +1,35 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Overlays.Processors; +using SixLabors.Primitives; + +namespace SixLabors.ImageSharp.Processing.Filters.Processors +{ + /// + /// Converts the colors of the image recreating an old Polaroid effect. + /// + /// The pixel format. + internal class PolaroidProcessor : FilterProcessor + where TPixel : struct, IPixel + { + private static readonly TPixel VeryDarkOrange = ColorBuilder.FromRGB(102, 34, 0); + private static readonly TPixel LightOrange = ColorBuilder.FromRGBA(255, 153, 102, 128); + + /// + /// Initializes a new instance of the class. + /// + public PolaroidProcessor() + : base(MatrixFilters.PolaroidFilter) + { + } + + /// + protected override void AfterFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) + { + new VignetteProcessor(VeryDarkOrange).Apply(source, sourceRectangle, configuration); + new GlowProcessor(LightOrange, source.Width / 4F).Apply(source, sourceRectangle, configuration); + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Processors/Filters/ColorBlindness/ProtanomalyProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/ProtanomalyProcessor.cs similarity index 92% rename from src/ImageSharp/Processing/Processors/Filters/ColorBlindness/ProtanomalyProcessor.cs rename to src/ImageSharp/Processing/Filters/Processors/ProtanomalyProcessor.cs index b7b61d5e59..4801391227 100644 --- a/src/ImageSharp/Processing/Processors/Filters/ColorBlindness/ProtanomalyProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/ProtanomalyProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Filters.Processors { /// /// Converts the colors of the image recreating Protanomaly (Red-Weak) color blindness. diff --git a/src/ImageSharp/Processing/Processors/Filters/ColorBlindness/ProtanopiaProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/ProtanopiaProcessor.cs similarity index 90% rename from src/ImageSharp/Processing/Processors/Filters/ColorBlindness/ProtanopiaProcessor.cs rename to src/ImageSharp/Processing/Filters/Processors/ProtanopiaProcessor.cs index 54753f5b57..43f1c14ea8 100644 --- a/src/ImageSharp/Processing/Processors/Filters/ColorBlindness/ProtanopiaProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/ProtanopiaProcessor.cs @@ -1,10 +1,9 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System.Numerics; using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Filters.Processors { /// /// Converts the colors of the image recreating Protanopia (Red-Blind) color blindness. diff --git a/src/ImageSharp/Processing/Processors/Filters/ColorBlindness/README.md b/src/ImageSharp/Processing/Filters/Processors/README.md similarity index 100% rename from src/ImageSharp/Processing/Processors/Filters/ColorBlindness/README.md rename to src/ImageSharp/Processing/Filters/Processors/README.md diff --git a/src/ImageSharp/Processing/Processors/Filters/SaturateProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/SaturateProcessor.cs similarity index 86% rename from src/ImageSharp/Processing/Processors/Filters/SaturateProcessor.cs rename to src/ImageSharp/Processing/Filters/Processors/SaturateProcessor.cs index 44b3fe3ced..9a48cb2b51 100644 --- a/src/ImageSharp/Processing/Processors/Filters/SaturateProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/SaturateProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Filters.Processors { /// /// Applies a saturation filter matrix using the given amount. @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Processing.Processors /// Initializes a new instance of the class. /// /// - /// A value of 0 is completely un-saturated. A value of 1 leaves the input unchanged. + /// A value of 0 is completely un-saturated. A value of 1 leaves the input unchanged. /// Other values are linear multipliers on the effect. Values of amount over 1 are allowed, providing super-saturated results /// /// The proportion of the conversion. Must be greater than or equal to 0. diff --git a/src/ImageSharp/Processing/Processors/Filters/SepiaProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/SepiaProcessor.cs similarity index 93% rename from src/ImageSharp/Processing/Processors/Filters/SepiaProcessor.cs rename to src/ImageSharp/Processing/Filters/Processors/SepiaProcessor.cs index b30d0fe052..2b3bf105bf 100644 --- a/src/ImageSharp/Processing/Processors/Filters/SepiaProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/SepiaProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Filters.Processors { /// /// Applies a sepia filter matrix using the given amount. diff --git a/src/ImageSharp/Processing/Processors/Filters/ColorBlindness/TritanomalyProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/TritanomalyProcessor.cs similarity index 92% rename from src/ImageSharp/Processing/Processors/Filters/ColorBlindness/TritanomalyProcessor.cs rename to src/ImageSharp/Processing/Filters/Processors/TritanomalyProcessor.cs index 57f4d4fa83..cd2e382178 100644 --- a/src/ImageSharp/Processing/Processors/Filters/ColorBlindness/TritanomalyProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/TritanomalyProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Filters.Processors { /// /// Converts the colors of the image recreating Tritanomaly (Blue-Weak) color blindness. diff --git a/src/ImageSharp/Processing/Processors/Filters/ColorBlindness/TritanopiaProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/TritanopiaProcessor.cs similarity index 92% rename from src/ImageSharp/Processing/Processors/Filters/ColorBlindness/TritanopiaProcessor.cs rename to src/ImageSharp/Processing/Filters/Processors/TritanopiaProcessor.cs index b03a18cf76..ce4a079a27 100644 --- a/src/ImageSharp/Processing/Processors/Filters/ColorBlindness/TritanopiaProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/TritanopiaProcessor.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Filters.Processors { /// /// Converts the colors of the image recreating Tritanopia (Blue-Blind) color blindness. diff --git a/src/ImageSharp/Processing/ColorMatrix/Saturate.cs b/src/ImageSharp/Processing/Filters/SaturateExtensions.cs similarity index 82% rename from src/ImageSharp/Processing/ColorMatrix/Saturate.cs rename to src/ImageSharp/Processing/Filters/SaturateExtensions.cs index c7dd395aa3..282bdef64c 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Saturate.cs +++ b/src/ImageSharp/Processing/Filters/SaturateExtensions.cs @@ -2,15 +2,15 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Filters.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Filters { /// - /// Extension methods for the type. + /// Adds extensions that allow the alteration of the saturation component to the type. /// - public static partial class ImageExtensions + public static class SaturateExtensions { /// /// Alters the saturation component of the image. @@ -25,10 +25,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Saturate(this IImageProcessingContext source, float amount) where TPixel : struct, IPixel - { - source.ApplyProcessor(new SaturateProcessor(amount)); - return source; - } + => source.ApplyProcessor(new SaturateProcessor(amount)); /// /// Alters the saturation component of the image. @@ -46,9 +43,6 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Saturate(this IImageProcessingContext source, float amount, Rectangle rectangle) where TPixel : struct, IPixel - { - source.ApplyProcessor(new SaturateProcessor(amount), rectangle); - return source; - } + => source.ApplyProcessor(new SaturateProcessor(amount), rectangle); } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/ColorMatrix/Sepia.cs b/src/ImageSharp/Processing/Filters/SepiaExtensions.cs similarity index 91% rename from src/ImageSharp/Processing/ColorMatrix/Sepia.cs rename to src/ImageSharp/Processing/Filters/SepiaExtensions.cs index 0d686f4dba..09d8c36843 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Sepia.cs +++ b/src/ImageSharp/Processing/Filters/SepiaExtensions.cs @@ -2,15 +2,15 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Filters.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Filters { /// - /// Extension methods for the type. + /// Adds extensions that allow the application of sepia toning to the type. /// - public static partial class ImageExtensions + public static class SepiaExtensions { /// /// Applies sepia toning to the image. diff --git a/src/ImageSharp/IImageProcessingContextFactory.cs b/src/ImageSharp/Processing/IImageProcessingContextFactory.cs similarity index 86% rename from src/ImageSharp/IImageProcessingContextFactory.cs rename to src/ImageSharp/Processing/IImageProcessingContextFactory.cs index b7b935ecd5..1ec2d191f3 100644 --- a/src/ImageSharp/IImageProcessingContextFactory.cs +++ b/src/ImageSharp/Processing/IImageProcessingContextFactory.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing { /// /// Represents an interface that will create IInternalImageProcessingContext instances @@ -16,13 +16,13 @@ namespace SixLabors.ImageSharp /// The pixel format /// The source image. /// A flag to determine whether image operations are allowed to mutate the source image. - /// A new IImageOPeration + /// A new IInternalImageProcessingContext CreateImageProcessingContext(Image source, bool mutate) where TPixel : struct, IPixel; } /// - /// The default implmentation of + /// The default implementation of /// internal class DefaultImageOperationsProviderFactory : IImageProcessingContextFactory { @@ -33,4 +33,4 @@ namespace SixLabors.ImageSharp return new DefaultInternalImageProcessorContext(source, mutate); } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/IImageProcessingContext{TPixel}.cs b/src/ImageSharp/Processing/IImageProcessingContext{TPixel}.cs similarity index 96% rename from src/ImageSharp/IImageProcessingContext{TPixel}.cs rename to src/ImageSharp/Processing/IImageProcessingContext{TPixel}.cs index 0e8efde3b3..f56777bedb 100644 --- a/src/ImageSharp/IImageProcessingContext{TPixel}.cs +++ b/src/ImageSharp/Processing/IImageProcessingContext{TPixel}.cs @@ -3,10 +3,10 @@ using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing { /// /// An interface to queue up image operations to apply to an image. diff --git a/src/ImageSharp/Processing/Effects/BackgroundColor.cs b/src/ImageSharp/Processing/Overlays/BackgroundColorExtensions.cs similarity index 82% rename from src/ImageSharp/Processing/Effects/BackgroundColor.cs rename to src/ImageSharp/Processing/Overlays/BackgroundColorExtensions.cs index 22aad9ca6a..72cba78e54 100644 --- a/src/ImageSharp/Processing/Effects/BackgroundColor.cs +++ b/src/ImageSharp/Processing/Overlays/BackgroundColorExtensions.cs @@ -1,17 +1,16 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Overlays.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Overlays { /// - /// Extension methods for the type. + /// Adds extensions that allow the application of a background color to the type. /// - public static partial class ImageExtensions + public static class BackgroundColorExtensions { /// /// Replaces the background color of image with the given one. @@ -19,11 +18,10 @@ namespace SixLabors.ImageSharp /// The pixel format. /// The image this method extends. /// The color to set as the background. - /// The options effecting pixel blending. /// The . - public static IImageProcessingContext BackgroundColor(this IImageProcessingContext source, TPixel color, GraphicsOptions options) + public static IImageProcessingContext BackgroundColor(this IImageProcessingContext source, TPixel color) where TPixel : struct, IPixel - => source.ApplyProcessor(new BackgroundColorProcessor(source.MemoryManager, color, options)); + => BackgroundColor(source, color, GraphicsOptions.Default); /// /// Replaces the background color of image with the given one. @@ -34,11 +32,10 @@ namespace SixLabors.ImageSharp /// /// The structure that specifies the portion of the image object to alter. /// - /// The options effecting pixel blending. /// The . - public static IImageProcessingContext BackgroundColor(this IImageProcessingContext source, TPixel color, Rectangle rectangle, GraphicsOptions options) + public static IImageProcessingContext BackgroundColor(this IImageProcessingContext source, TPixel color, Rectangle rectangle) where TPixel : struct, IPixel - => source.ApplyProcessor(new BackgroundColorProcessor(source.MemoryManager, color, options), rectangle); + => BackgroundColor(source, color, rectangle, GraphicsOptions.Default); /// /// Replaces the background color of image with the given one. @@ -46,12 +43,11 @@ namespace SixLabors.ImageSharp /// The pixel format. /// The image this method extends. /// The color to set as the background. + /// The options effecting pixel blending. /// The . - public static IImageProcessingContext BackgroundColor(this IImageProcessingContext source, TPixel color) + public static IImageProcessingContext BackgroundColor(this IImageProcessingContext source, TPixel color, GraphicsOptions options) where TPixel : struct, IPixel - { - return BackgroundColor(source, color, GraphicsOptions.Default); - } + => source.ApplyProcessor(new BackgroundColorProcessor(color, options)); /// /// Replaces the background color of image with the given one. @@ -62,11 +58,10 @@ namespace SixLabors.ImageSharp /// /// The structure that specifies the portion of the image object to alter. /// + /// The options effecting pixel blending. /// The . - public static IImageProcessingContext BackgroundColor(this IImageProcessingContext source, TPixel color, Rectangle rectangle) + public static IImageProcessingContext BackgroundColor(this IImageProcessingContext source, TPixel color, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel - { - return BackgroundColor(source, color, rectangle, GraphicsOptions.Default); - } + => source.ApplyProcessor(new BackgroundColorProcessor(color, options), rectangle); } } diff --git a/src/ImageSharp/Processing/Overlays/Glow.cs b/src/ImageSharp/Processing/Overlays/GlowExtensions.cs similarity index 87% rename from src/ImageSharp/Processing/Overlays/Glow.cs rename to src/ImageSharp/Processing/Overlays/GlowExtensions.cs index 0c3552b4d2..a86128f88d 100644 --- a/src/ImageSharp/Processing/Overlays/Glow.cs +++ b/src/ImageSharp/Processing/Overlays/GlowExtensions.cs @@ -2,15 +2,16 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Primitives; +using SixLabors.ImageSharp.Processing.Overlays.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Overlays { /// - /// Extension methods for the type. + /// Adds extensions that allow the application of a radial glow to the type. /// - public static partial class ImageExtensions + public static class GlowExtensions { /// /// Applies a radial glow effect to an image. @@ -20,9 +21,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Glow(this IImageProcessingContext source) where TPixel : struct, IPixel - { - return Glow(source, GraphicsOptions.Default); - } + => Glow(source, GraphicsOptions.Default); /// /// Applies a radial glow effect to an image. @@ -46,9 +45,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Glow(this IImageProcessingContext source, float radius) where TPixel : struct, IPixel - { - return Glow(source, radius, GraphicsOptions.Default); - } + => Glow(source, radius, GraphicsOptions.Default); /// /// Applies a radial glow effect to an image. @@ -61,7 +58,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Glow(this IImageProcessingContext source, Rectangle rectangle) where TPixel : struct, IPixel - => source.Glow(rectangle, GraphicsOptions.Default); + => source.Glow(rectangle, GraphicsOptions.Default); /// /// Applies a radial glow effect to an image. @@ -76,7 +73,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Glow(this IImageProcessingContext source, TPixel color, float radius, Rectangle rectangle) where TPixel : struct, IPixel - => source.Glow(color, ValueSize.Absolute(radius), rectangle, GraphicsOptions.Default); + => source.Glow(color, ValueSize.Absolute(radius), rectangle, GraphicsOptions.Default); /// /// Applies a radial glow effect to an image. @@ -87,7 +84,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Glow(this IImageProcessingContext source, GraphicsOptions options) where TPixel : struct, IPixel - => source.Glow(NamedColors.Black, ValueSize.PercentageOfWidth(0.5f), options); + => source.Glow(NamedColors.Black, ValueSize.PercentageOfWidth(0.5f), options); /// /// Applies a radial glow effect to an image. @@ -99,7 +96,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Glow(this IImageProcessingContext source, TPixel color, GraphicsOptions options) where TPixel : struct, IPixel - => source.Glow(color, ValueSize.PercentageOfWidth(0.5f), options); + => source.Glow(color, ValueSize.PercentageOfWidth(0.5f), options); /// /// Applies a radial glow effect to an image. @@ -111,7 +108,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Glow(this IImageProcessingContext source, float radius, GraphicsOptions options) where TPixel : struct, IPixel - => source.Glow(NamedColors.Black, ValueSize.Absolute(radius), options); + => source.Glow(NamedColors.Black, ValueSize.Absolute(radius), options); /// /// Applies a radial glow effect to an image. @@ -125,7 +122,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Glow(this IImageProcessingContext source, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel - => source.Glow(NamedColors.Black, ValueSize.PercentageOfWidth(0.5f), rectangle, options); + => source.Glow(NamedColors.Black, ValueSize.PercentageOfWidth(0.5f), rectangle, options); /// /// Applies a radial glow effect to an image. @@ -141,7 +138,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Glow(this IImageProcessingContext source, TPixel color, float radius, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel - => source.Glow(color, ValueSize.Absolute(radius), rectangle, options); + => source.Glow(color, ValueSize.Absolute(radius), rectangle, options); /// /// Applies a radial glow effect to an image. @@ -157,7 +154,7 @@ namespace SixLabors.ImageSharp /// The . private static IImageProcessingContext Glow(this IImageProcessingContext source, TPixel color, ValueSize radius, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel - => source.ApplyProcessor(new GlowProcessor(source.MemoryManager, color, radius, options), rectangle); + => source.ApplyProcessor(new GlowProcessor(color, radius, options), rectangle); /// /// Applies a radial glow effect to an image. @@ -170,6 +167,6 @@ namespace SixLabors.ImageSharp /// The . private static IImageProcessingContext Glow(this IImageProcessingContext source, TPixel color, ValueSize radius, GraphicsOptions options) where TPixel : struct, IPixel - => source.ApplyProcessor(new GlowProcessor(source.MemoryManager, color, radius, options)); + => source.ApplyProcessor(new GlowProcessor(color, radius, options)); } } diff --git a/src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs b/src/ImageSharp/Processing/Overlays/Processors/BackgroundColorProcessor.cs similarity index 66% rename from src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs rename to src/ImageSharp/Processing/Overlays/Processors/BackgroundColorProcessor.cs index 720b876913..b676f6a122 100644 --- a/src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs +++ b/src/ImageSharp/Processing/Overlays/Processors/BackgroundColorProcessor.cs @@ -6,9 +6,10 @@ using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Overlays.Processors { /// /// Sets the background color of the image. @@ -17,35 +18,29 @@ namespace SixLabors.ImageSharp.Processing.Processors internal class BackgroundColorProcessor : ImageProcessor where TPixel : struct, IPixel { - private readonly MemoryManager memoryManager; - - private readonly GraphicsOptions options; - /// /// Initializes a new instance of the class. /// - /// The to use for buffer allocations. /// The to set the background color to. - /// The options defining blending algorithum and amount. - public BackgroundColorProcessor(MemoryManager memoryManager, TPixel color, GraphicsOptions options) + /// The options defining blending algorithm and amount. + public BackgroundColorProcessor(TPixel color, GraphicsOptions options) { - this.Value = color; - this.memoryManager = memoryManager; - this.options = options; + this.Color = color; + this.GraphicsOptions = options; } /// /// Gets the Graphics options to alter how processor is applied. /// - public GraphicsOptions GraphicsOptions => this.options; + public GraphicsOptions GraphicsOptions { get; } /// /// Gets the background color value. /// - public TPixel Value { get; } + public TPixel Color { get; } /// - protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) + protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { int startY = sourceRectangle.Y; int endY = sourceRectangle.Bottom; @@ -71,20 +66,21 @@ namespace SixLabors.ImageSharp.Processing.Processors int width = maxX - minX; - using (IBuffer colors = this.memoryManager.Allocate(width)) - using (IBuffer amount = this.memoryManager.Allocate(width)) + using (IBuffer colors = source.MemoryManager.Allocate(width)) + using (IBuffer amount = source.MemoryManager.Allocate(width)) { // Be careful! Do not capture colorSpan & amountSpan in the lambda below! Span colorSpan = colors.Span; Span amountSpan = amount.Span; + // TODO: Use Span.Fill? for (int i = 0; i < width; i++) { - colorSpan[i] = this.Value; - amountSpan[i] = this.options.BlendPercentage; + colorSpan[i] = this.Color; + amountSpan[i] = this.GraphicsOptions.BlendPercentage; } - PixelBlender blender = PixelOperations.Instance.GetPixelBlender(this.options.BlenderMode); + PixelBlender blender = PixelOperations.Instance.GetPixelBlender(this.GraphicsOptions.BlenderMode); Parallel.For( minY, maxY, @@ -93,8 +89,8 @@ namespace SixLabors.ImageSharp.Processing.Processors { Span destination = source.GetPixelRowSpan(y - startY).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(this.memoryManager, destination, colors.Span, destination, amount.Span); + // This switched color & destination in the 2nd and 3rd places because we are applying the target color under the current one + blender.Blend(source.MemoryManager, destination, colors.Span, destination, amount.Span); }); } } diff --git a/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs b/src/ImageSharp/Processing/Overlays/Processors/GlowProcessor.cs similarity index 61% rename from src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs rename to src/ImageSharp/Processing/Overlays/Processors/GlowProcessor.cs index 9ab301718c..ac5d3dc82e 100644 --- a/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs +++ b/src/ImageSharp/Processing/Overlays/Processors/GlowProcessor.cs @@ -5,12 +5,13 @@ using System; using System.Numerics; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Helpers; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Primitives; +using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Overlays.Processors { /// /// An that applies a radial glow effect an . @@ -19,31 +20,55 @@ namespace SixLabors.ImageSharp.Processing.Processors internal class GlowProcessor : ImageProcessor where TPixel : struct, IPixel { - private readonly MemoryManager memoryManager; - - private readonly GraphicsOptions options; private readonly PixelBlender blender; /// /// Initializes a new instance of the class. /// - /// The to use for buffer allocations. + /// The color or the glow. + public GlowProcessor(TPixel color) + : this(color, 0) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The color or the glow. + /// The radius of the glow. + public GlowProcessor(TPixel color, ValueSize radius) + : this(color, radius, GraphicsOptions.Default) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The color or the glow. + /// The options effecting blending and composition. + public GlowProcessor(TPixel color, GraphicsOptions options) + : this(color, 0, options) + { + } + + /// + /// Initializes a new instance of the class. + /// /// The color or the glow. /// The radius of the glow. /// The options effecting blending and composition. - public GlowProcessor(MemoryManager memoryManager, TPixel color, ValueSize radius, GraphicsOptions options) + public GlowProcessor(TPixel color, ValueSize radius, GraphicsOptions options) { - this.memoryManager = memoryManager; - this.options = options; this.GlowColor = color; this.Radius = radius; - this.blender = PixelOperations.Instance.GetPixelBlender(this.options.BlenderMode); + this.blender = PixelOperations.Instance.GetPixelBlender(options.BlenderMode); + this.GraphicsOptions = options; } /// - /// Gets the Graphics options to alter how processor is applied. + /// Gets the options effecting blending and composition /// - public GraphicsOptions GraphicsOptions => this.options; + public GraphicsOptions GraphicsOptions { get; } /// /// Gets or sets the glow color to apply. @@ -56,14 +81,14 @@ namespace SixLabors.ImageSharp.Processing.Processors public ValueSize Radius { get; set; } /// - protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) + protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { int startY = sourceRectangle.Y; int endY = sourceRectangle.Bottom; int startX = sourceRectangle.X; int endX = sourceRectangle.Right; TPixel glowColor = this.GlowColor; - Vector2 centre = Rectangle.Center(sourceRectangle); + Vector2 center = Rectangle.Center(sourceRectangle); float finalRadius = this.Radius.Calculate(source.Size()); @@ -87,7 +112,7 @@ namespace SixLabors.ImageSharp.Processing.Processors } int width = maxX - minX; - using (IBuffer rowColors = this.memoryManager.Allocate(width)) + using (IBuffer rowColors = source.MemoryManager.Allocate(width)) { // Be careful! Do not capture rowColorsSpan in the lambda below! Span rowColorsSpan = rowColors.Span; @@ -103,20 +128,20 @@ namespace SixLabors.ImageSharp.Processing.Processors configuration.ParallelOptions, y => { - using (IBuffer amounts = this.memoryManager.Allocate(width)) + using (IBuffer amounts = source.MemoryManager.Allocate(width)) { Span amountsSpan = amounts.Span; int offsetY = y - startY; int offsetX = minX - startX; for (int i = 0; i < width; i++) { - float distance = Vector2.Distance(centre, new Vector2(i + offsetX, offsetY)); - amountsSpan[i] = (this.options.BlendPercentage * (1 - (.95F * (distance / maxDistance)))).Clamp(0, 1); + float distance = Vector2.Distance(center, new Vector2(i + offsetX, offsetY)); + amountsSpan[i] = (this.GraphicsOptions.BlendPercentage * (1 - (.95F * (distance / maxDistance)))).Clamp(0, 1); } Span destination = source.GetPixelRowSpan(offsetY).Slice(offsetX, width); - this.blender.Blend(this.memoryManager, destination, destination, rowColors.Span, amountsSpan); + this.blender.Blend(source.MemoryManager, destination, destination, rowColors.Span, amountsSpan); } }); } diff --git a/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs b/src/ImageSharp/Processing/Overlays/Processors/VignetteProcessor.cs similarity index 69% rename from src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs rename to src/ImageSharp/Processing/Overlays/Processors/VignetteProcessor.cs index d47211f0cb..ec286db626 100644 --- a/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs +++ b/src/ImageSharp/Processing/Overlays/Processors/VignetteProcessor.cs @@ -5,12 +5,13 @@ using System; using System.Numerics; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Helpers; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Primitives; +using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Overlays.Processors { /// /// An that applies a radial vignette effect to an . @@ -19,47 +20,49 @@ namespace SixLabors.ImageSharp.Processing.Processors internal class VignetteProcessor : ImageProcessor where TPixel : struct, IPixel { - private readonly MemoryManager memoryManager; - - private readonly GraphicsOptions options; private readonly PixelBlender blender; /// /// Initializes a new instance of the class. /// - /// The to use for buffer allocations. /// The color of the vignette. - /// The x-radius. - /// The y-radius. + public VignetteProcessor(TPixel color) + : this(color, GraphicsOptions.Default) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The color of the vignette. /// The options effecting blending and composition. - public VignetteProcessor(MemoryManager memoryManager, TPixel color, ValueSize radiusX, ValueSize radiusY, GraphicsOptions options) + public VignetteProcessor(TPixel color, GraphicsOptions options) { this.VignetteColor = color; - this.RadiusX = radiusX; - this.RadiusY = radiusY; - this.memoryManager = memoryManager; - this.options = options; - this.blender = PixelOperations.Instance.GetPixelBlender(this.options.BlenderMode); + this.GraphicsOptions = options; + this.blender = PixelOperations.Instance.GetPixelBlender(options.BlenderMode); } /// /// Initializes a new instance of the class. /// - /// The to use for buffer allocations. /// The color of the vignette. + /// The x-radius. + /// The y-radius. /// The options effecting blending and composition. - public VignetteProcessor(MemoryManager memoryManager, TPixel color, GraphicsOptions options) + public VignetteProcessor(TPixel color, ValueSize radiusX, ValueSize radiusY, GraphicsOptions options) { this.VignetteColor = color; - this.memoryManager = memoryManager; - this.options = options; - this.blender = PixelOperations.Instance.GetPixelBlender(this.options.BlenderMode); + this.RadiusX = radiusX; + this.RadiusY = radiusY; + this.blender = PixelOperations.Instance.GetPixelBlender(options.BlenderMode); + this.GraphicsOptions = options; } /// - /// Gets the Graphics options to alter how processor is applied. + /// Gets the options effecting blending and composition /// - public GraphicsOptions GraphicsOptions => this.options; + public GraphicsOptions GraphicsOptions { get; } /// /// Gets or sets the vignette color to apply. @@ -77,7 +80,7 @@ namespace SixLabors.ImageSharp.Processing.Processors public ValueSize RadiusY { get; set; } /// - protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) + protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { int startY = sourceRectangle.Y; int endY = sourceRectangle.Bottom; @@ -86,10 +89,11 @@ namespace SixLabors.ImageSharp.Processing.Processors TPixel vignetteColor = this.VignetteColor; Vector2 centre = Rectangle.Center(sourceRectangle); - float finalradiusX = this.RadiusX.Calculate(source.Size()); - float finalradiusY = this.RadiusY.Calculate(source.Size()); - float rX = finalradiusX > 0 ? MathF.Min(finalradiusX, sourceRectangle.Width * .5F) : sourceRectangle.Width * .5F; - float rY = finalradiusY > 0 ? MathF.Min(finalradiusY, sourceRectangle.Height * .5F) : sourceRectangle.Height * .5F; + Size sourceSize = source.Size(); + float finalRadiusX = this.RadiusX.Calculate(sourceSize); + float finalRadiusY = this.RadiusY.Calculate(sourceSize); + float rX = finalRadiusX > 0 ? MathF.Min(finalRadiusX, sourceRectangle.Width * .5F) : sourceRectangle.Width * .5F; + float rY = finalRadiusY > 0 ? MathF.Min(finalRadiusY, sourceRectangle.Height * .5F) : sourceRectangle.Height * .5F; float maxDistance = MathF.Sqrt((rX * rX) + (rY * rY)); // Align start/end positions. @@ -110,7 +114,7 @@ namespace SixLabors.ImageSharp.Processing.Processors } int width = maxX - minX; - using (IBuffer rowColors = this.memoryManager.Allocate(width)) + using (IBuffer rowColors = source.MemoryManager.Allocate(width)) { // Be careful! Do not capture rowColorsSpan in the lambda below! Span rowColorsSpan = rowColors.Span; @@ -126,7 +130,7 @@ namespace SixLabors.ImageSharp.Processing.Processors configuration.ParallelOptions, y => { - using (IBuffer amounts = this.memoryManager.Allocate(width)) + using (IBuffer amounts = source.MemoryManager.Allocate(width)) { Span amountsSpan = amounts.Span; int offsetY = y - startY; @@ -134,12 +138,12 @@ namespace SixLabors.ImageSharp.Processing.Processors for (int i = 0; i < width; i++) { float distance = Vector2.Distance(centre, new Vector2(i + offsetX, offsetY)); - amountsSpan[i] = (this.options.BlendPercentage * (.9F * (distance / maxDistance))).Clamp(0, 1); + amountsSpan[i] = (this.GraphicsOptions.BlendPercentage * (.9F * (distance / maxDistance))).Clamp(0, 1); } Span destination = source.GetPixelRowSpan(offsetY).Slice(offsetX, width); - this.blender.Blend(this.memoryManager, destination, destination, rowColors.Span, amountsSpan); + this.blender.Blend(source.MemoryManager, destination, destination, rowColors.Span, amountsSpan); } }); } diff --git a/src/ImageSharp/Processing/Overlays/Vignette.cs b/src/ImageSharp/Processing/Overlays/VignetteExtensions.cs similarity index 85% rename from src/ImageSharp/Processing/Overlays/Vignette.cs rename to src/ImageSharp/Processing/Overlays/VignetteExtensions.cs index 4b9f2f866c..e533c914ff 100644 --- a/src/ImageSharp/Processing/Overlays/Vignette.cs +++ b/src/ImageSharp/Processing/Overlays/VignetteExtensions.cs @@ -2,15 +2,16 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Primitives; +using SixLabors.ImageSharp.Processing.Overlays.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Overlays { /// - /// Extension methods for the type. + /// Adds extensions that allow the application of a radial glow to the type. /// - public static partial class ImageExtensions + public static class VignetteExtensions { /// /// Applies a radial vignette effect to an image. @@ -20,9 +21,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Vignette(this IImageProcessingContext source) where TPixel : struct, IPixel - { - return Vignette(source, GraphicsOptions.Default); - } + => Vignette(source, GraphicsOptions.Default); /// /// Applies a radial vignette effect to an image. @@ -33,9 +32,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Vignette(this IImageProcessingContext source, TPixel color) where TPixel : struct, IPixel - { - return Vignette(source, color, GraphicsOptions.Default); - } + => Vignette(source, color, GraphicsOptions.Default); /// /// Applies a radial vignette effect to an image. @@ -47,9 +44,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Vignette(this IImageProcessingContext source, float radiusX, float radiusY) where TPixel : struct, IPixel - { - return Vignette(source, radiusX, radiusY, GraphicsOptions.Default); - } + => Vignette(source, radiusX, radiusY, GraphicsOptions.Default); /// /// Applies a radial vignette effect to an image. @@ -62,9 +57,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Vignette(this IImageProcessingContext source, Rectangle rectangle) where TPixel : struct, IPixel - { - return Vignette(source, rectangle, GraphicsOptions.Default); - } + => Vignette(source, rectangle, GraphicsOptions.Default); /// /// Applies a radial vignette effect to an image. @@ -80,7 +73,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Vignette(this IImageProcessingContext source, TPixel color, float radiusX, float radiusY, Rectangle rectangle) where TPixel : struct, IPixel - => source.Vignette(color, radiusX, radiusY, rectangle, GraphicsOptions.Default); + => source.Vignette(color, radiusX, radiusY, rectangle, GraphicsOptions.Default); /// /// Applies a radial vignette effect to an image. @@ -91,7 +84,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Vignette(this IImageProcessingContext source, GraphicsOptions options) where TPixel : struct, IPixel - => source.VignetteInternal(NamedColors.Black, ValueSize.PercentageOfWidth(.5f), ValueSize.PercentageOfHeight(.5f), options); + => source.VignetteInternal(NamedColors.Black, ValueSize.PercentageOfWidth(.5f), ValueSize.PercentageOfHeight(.5f), options); /// /// Applies a radial vignette effect to an image. @@ -103,7 +96,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Vignette(this IImageProcessingContext source, TPixel color, GraphicsOptions options) where TPixel : struct, IPixel - => source.VignetteInternal(color, ValueSize.PercentageOfWidth(.5f), ValueSize.PercentageOfHeight(.5f), options); + => source.VignetteInternal(color, ValueSize.PercentageOfWidth(.5f), ValueSize.PercentageOfHeight(.5f), options); /// /// Applies a radial vignette effect to an image. @@ -116,7 +109,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Vignette(this IImageProcessingContext source, float radiusX, float radiusY, GraphicsOptions options) where TPixel : struct, IPixel - => source.VignetteInternal(NamedColors.Black, radiusX, radiusY, options); + => source.VignetteInternal(NamedColors.Black, radiusX, radiusY, options); /// /// Applies a radial vignette effect to an image. @@ -130,7 +123,7 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Vignette(this IImageProcessingContext source, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel - => source.VignetteInternal(NamedColors.Black, ValueSize.PercentageOfWidth(.5f), ValueSize.PercentageOfHeight(.5f), rectangle, options); + => source.VignetteInternal(NamedColors.Black, ValueSize.PercentageOfWidth(.5f), ValueSize.PercentageOfHeight(.5f), rectangle, options); /// /// Applies a radial vignette effect to an image. @@ -147,14 +140,14 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Vignette(this IImageProcessingContext source, TPixel color, float radiusX, float radiusY, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel - => source.VignetteInternal(color, radiusX, radiusY, rectangle, options); + => source.VignetteInternal(color, radiusX, radiusY, rectangle, options); private static IImageProcessingContext VignetteInternal(this IImageProcessingContext source, TPixel color, ValueSize radiusX, ValueSize radiusY, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel - => source.ApplyProcessor(new VignetteProcessor(source.MemoryManager, color, radiusX, radiusY, options), rectangle); + => source.ApplyProcessor(new VignetteProcessor(color, radiusX, radiusY, options), rectangle); private static IImageProcessingContext VignetteInternal(this IImageProcessingContext source, TPixel color, ValueSize radiusX, ValueSize radiusY, GraphicsOptions options) where TPixel : struct, IPixel - => source.ApplyProcessor(new VignetteProcessor(source.MemoryManager, color, radiusX, radiusY, options)); + => source.ApplyProcessor(new VignetteProcessor(color, radiusX, radiusY, options)); } } \ No newline at end of file diff --git a/src/ImageSharp/ApplyProcessors.cs b/src/ImageSharp/Processing/ProcessingExtensions.cs similarity index 75% rename from src/ImageSharp/ApplyProcessors.cs rename to src/ImageSharp/Processing/ProcessingExtensions.cs index c4954ef0d1..9d06c61d4c 100644 --- a/src/ImageSharp/ApplyProcessors.cs +++ b/src/ImageSharp/Processing/ProcessingExtensions.cs @@ -4,14 +4,27 @@ using System; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing { /// - /// Extension methods for the type. + /// Adds extensions that allow the processing of images to the type. /// - public static partial class ImageExtensions + public static class ProcessingExtensions { + /// + /// Applies the given operation to the mutable image. + /// Useful when we need to extract information like Width/Height to parametrize the next operation working on the chain. + /// To achieve this the method actually implements an "inline" with as it's processing logic. + /// + /// The pixel format. + /// The image to mutate. + /// The operation to perform on the source. + /// The to allow chaining of operations. + public static IImageProcessingContext Apply(this IImageProcessingContext source, Action> operation) + where TPixel : struct, IPixel => source.ApplyProcessor(new DelegateProcessor(operation)); + /// /// Mutates the source image by applying the image operation to it. /// @@ -52,7 +65,7 @@ namespace SixLabors.ImageSharp /// The pixel format. /// The image to clone. /// The operation to perform on the clone. - /// The new + /// The new public static Image Clone(this Image source, Action> operation) where TPixel : struct, IPixel { @@ -70,7 +83,7 @@ namespace SixLabors.ImageSharp /// The pixel format. /// The image to clone. /// The operations to perform on the clone. - /// The new + /// The new public static Image Clone(this Image source, params IImageProcessor[] operations) where TPixel : struct, IPixel { @@ -88,9 +101,9 @@ namespace SixLabors.ImageSharp /// The pixel format. /// The image processing context. /// The operations to perform on the source. - /// The to allow chaining of operations. + /// The to allow chaining of operations. public static IImageProcessingContext ApplyProcessors(this IImageProcessingContext source, params IImageProcessor[] operations) - where TPixel : struct, IPixel + where TPixel : struct, IPixel { foreach (IImageProcessor p in operations) { diff --git a/src/ImageSharp/Processing/Processors/CloningImageProcessor.cs b/src/ImageSharp/Processing/Processors/CloningImageProcessor.cs index 7257bd6643..ec342dd9fe 100644 --- a/src/ImageSharp/Processing/Processors/CloningImageProcessor.cs +++ b/src/ImageSharp/Processing/Processors/CloningImageProcessor.cs @@ -6,10 +6,10 @@ using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing.Processors { /// - /// Allows the application of processors to images. + /// Allows the application of processing algorithms to a clone of the original image. /// /// The pixel format. internal abstract class CloningImageProcessor : ICloningImageProcessor @@ -35,9 +35,9 @@ namespace SixLabors.ImageSharp.Processing ImageFrame sourceFrame = source.Frames[i]; ImageFrame clonedFrame = clone.Frames[i]; - this.BeforeApply(sourceFrame, clonedFrame, sourceRectangle, configuration); - this.OnApply(sourceFrame, clonedFrame, sourceRectangle, configuration); - this.AfterApply(sourceFrame, clonedFrame, sourceRectangle, configuration); + this.BeforeFrameApply(sourceFrame, clonedFrame, sourceRectangle, configuration); + this.OnFrameApply(sourceFrame, clonedFrame, sourceRectangle, configuration); + this.AfterFrameApply(sourceFrame, clonedFrame, sourceRectangle, configuration); } this.AfterImageApply(source, clone, sourceRectangle); @@ -51,7 +51,7 @@ namespace SixLabors.ImageSharp.Processing #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); + throw new ImageProcessingException($"An error occurred when processing the image using {this.GetType().Name}. See the inner exception for more detail.", ex); #endif } } @@ -96,36 +96,33 @@ namespace SixLabors.ImageSharp.Processing /// /// This method is called before the process is applied to prepare the processor. - /// TODO: We should probably name this 'BeforeFrameApply' /// /// The source image. Cannot be null. /// The cloned/destination image. Cannot be null. /// The structure that specifies the portion of the image object to draw. /// The configuration. - protected virtual void BeforeApply(ImageFrame source, ImageFrame destination, Rectangle sourceRectangle, Configuration configuration) + protected virtual void BeforeFrameApply(ImageFrame source, ImageFrame destination, Rectangle sourceRectangle, Configuration configuration) { } /// /// Applies the process to the specified portion of the specified at the specified location /// and with the specified size. - /// TODO: We should probably name this 'ApplyToFrame' /// /// The source image. Cannot be null. /// The cloned/destination image. Cannot be null. /// The structure that specifies the portion of the image object to draw. /// The configuration. - protected abstract void OnApply(ImageFrame source, ImageFrame destination, Rectangle sourceRectangle, Configuration configuration); + protected abstract void OnFrameApply(ImageFrame source, ImageFrame destination, Rectangle sourceRectangle, Configuration configuration); /// /// This method is called after the process is applied to prepare the processor. - /// TODO: We should probably name this 'AfterFrameApply' /// /// The source image. Cannot be null. /// The cloned/destination image. Cannot be null. /// The structure that specifies the portion of the image object to draw. /// The configuration. - protected virtual void AfterApply(ImageFrame source, ImageFrame destination, Rectangle sourceRectangle, Configuration configuration) + protected virtual void AfterFrameApply(ImageFrame source, ImageFrame destination, Rectangle sourceRectangle, Configuration configuration) { } diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs deleted file mode 100644 index 8e4cdd6b5a..0000000000 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; -using System.Diagnostics.CodeAnalysis; -using SixLabors.ImageSharp.Memory; -using SixLabors.ImageSharp.PixelFormats; - -namespace SixLabors.ImageSharp.Processing.Processors -{ - /// - /// The Kayyali operator filter. - /// - /// - /// The pixel format. - [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] - internal class KayyaliProcessor : EdgeDetector2DProcessor - where TPixel : struct, IPixel - { - /// - /// The horizontal gradient operator. - /// - private static readonly Fast2DArray KayyaliX = - new float[,] - { - { 6, 0, -6 }, - { 0, 0, 0 }, - { -6, 0, 6 } - }; - - /// - /// The vertical gradient operator. - /// - private static readonly Fast2DArray KayyaliY = - new float[,] - { - { -6, 0, 6 }, - { 0, 0, 0 }, - { 6, 0, -6 } - }; - - /// - /// Initializes a new instance of the class. - /// - public KayyaliProcessor() - : base(KayyaliX, KayyaliY) - { - } - } -} diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/KirschProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/KirschProcessor.cs deleted file mode 100644 index c0a3b35954..0000000000 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/KirschProcessor.cs +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; -using System.Diagnostics.CodeAnalysis; -using SixLabors.ImageSharp.Memory; -using SixLabors.ImageSharp.PixelFormats; - -namespace SixLabors.ImageSharp.Processing.Processors -{ - /// - /// The Kirsch operator filter. - /// - /// - /// The pixel format. - [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] - internal class KirschProcessor : EdgeDetectorCompassProcessor - where TPixel : struct, IPixel - { - /// - /// The North gradient operator - /// - private static readonly Fast2DArray KirschNorth = - new float[,] - { - { 5, 5, 5 }, - { -3, 0, -3 }, - { -3, -3, -3 } - }; - - /// - /// The NorthWest gradient operator - /// - private static readonly Fast2DArray KirschNorthWest = - new float[,] - { - { 5, 5, -3 }, - { 5, 0, -3 }, - { -3, -3, -3 } - }; - - /// - /// The West gradient operator - /// - private static readonly Fast2DArray KirschWest = - new float[,] - { - { 5, -3, -3 }, - { 5, 0, -3 }, - { 5, -3, -3 } - }; - - /// - /// The SouthWest gradient operator - /// - private static readonly Fast2DArray KirschSouthWest = - new float[,] - { - { -3, -3, -3 }, - { 5, 0, -3 }, - { 5, 5, -3 } - }; - - /// - /// The South gradient operator - /// - private static readonly Fast2DArray KirschSouth = - new float[,] - { - { -3, -3, -3 }, - { -3, 0, -3 }, - { 5, 5, 5 } - }; - - /// - /// The SouthEast gradient operator - /// - private static readonly Fast2DArray KirschSouthEast = - new float[,] - { - { -3, -3, -3 }, - { -3, 0, 5 }, - { -3, 5, 5 } - }; - - /// - /// The East gradient operator - /// - private static readonly Fast2DArray KirschEast = - new float[,] - { - { -3, -3, 5 }, - { -3, 0, 5 }, - { -3, -3, 5 } - }; - - /// - /// The NorthEast gradient operator - /// - private static readonly Fast2DArray KirschNorthEast = - new float[,] - { - { -3, 5, 5 }, - { -3, 0, 5 }, - { -3, -3, -3 } - }; - - /// - public override Fast2DArray North => KirschNorth; - - /// - public override Fast2DArray NorthWest => KirschNorthWest; - - /// - public override Fast2DArray West => KirschWest; - - /// - public override Fast2DArray SouthWest => KirschSouthWest; - - /// - public override Fast2DArray South => KirschSouth; - - /// - public override Fast2DArray SouthEast => KirschSouthEast; - - /// - public override Fast2DArray East => KirschEast; - - /// - public override Fast2DArray NorthEast => KirschNorthEast; - } -} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs deleted file mode 100644 index 1b5c563187..0000000000 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; -using System.Diagnostics.CodeAnalysis; -using SixLabors.ImageSharp.Memory; -using SixLabors.ImageSharp.PixelFormats; - -namespace SixLabors.ImageSharp.Processing.Processors -{ - /// - /// The Laplacian 3 x 3 operator filter. - /// - /// - /// The pixel format. - [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] - internal class Laplacian3X3Processor : EdgeDetectorProcessor - where TPixel : struct, IPixel - { - /// - /// The 2d gradient operator. - /// - private static readonly Fast2DArray Laplacian3X3XY = - new float[,] - { - { -1, -1, -1 }, - { -1, 8, -1 }, - { -1, -1, -1 } - }; - - /// - /// Initializes a new instance of the class. - /// - public Laplacian3X3Processor() - : base(Laplacian3X3XY) - { - } - } -} diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs deleted file mode 100644 index 11438fe8db..0000000000 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; -using System.Diagnostics.CodeAnalysis; -using SixLabors.ImageSharp.Memory; -using SixLabors.ImageSharp.PixelFormats; - -namespace SixLabors.ImageSharp.Processing.Processors -{ - /// - /// The Laplacian 5 x 5 operator filter. - /// - /// - /// The pixel format. - [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] - internal class Laplacian5X5Processor : EdgeDetectorProcessor - where TPixel : struct, IPixel - { - /// - /// The 2d gradient operator. - /// - private static readonly Fast2DArray Laplacian5X5XY = - new float[,] - { - { -1, -1, -1, -1, -1 }, - { -1, -1, -1, -1, -1 }, - { -1, -1, 24, -1, -1 }, - { -1, -1, -1, -1, -1 }, - { -1, -1, -1, -1, -1 } - }; - - /// - /// Initializes a new instance of the class. - /// - public Laplacian5X5Processor() - : base(Laplacian5X5XY) - { - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs deleted file mode 100644 index 424c01137e..0000000000 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; -using System.Diagnostics.CodeAnalysis; -using SixLabors.ImageSharp.Memory; -using SixLabors.ImageSharp.PixelFormats; - -namespace SixLabors.ImageSharp.Processing.Processors -{ - /// - /// The Laplacian of Gaussian operator filter. - /// - /// - /// The pixel format. - [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] - internal class LaplacianOfGaussianProcessor : EdgeDetectorProcessor - where TPixel : struct, IPixel - { - /// - /// The 2d gradient operator. - /// - private static readonly Fast2DArray LaplacianOfGaussianXY = - new float[,] - { - { 0, 0, -1, 0, 0 }, - { 0, -1, -2, -1, 0 }, - { -1, -2, 16, -2, -1 }, - { 0, -1, -2, -1, 0 }, - { 0, 0, -1, 0, 0 } - }; - - /// - /// Initializes a new instance of the class. - /// - public LaplacianOfGaussianProcessor() - : base(LaplacianOfGaussianXY) - { - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/PrewittProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/PrewittProcessor.cs deleted file mode 100644 index 0d2e9b2066..0000000000 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/PrewittProcessor.cs +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; -using System.Diagnostics.CodeAnalysis; -using SixLabors.ImageSharp.Memory; -using SixLabors.ImageSharp.PixelFormats; - -namespace SixLabors.ImageSharp.Processing.Processors -{ - /// - /// The Prewitt operator filter. - /// - /// - /// The pixel format. - [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] - internal class PrewittProcessor : EdgeDetector2DProcessor - where TPixel : struct, IPixel - { - /// - /// The horizontal gradient operator. - /// - private static readonly Fast2DArray PrewittX = - new float[,] - { - { -1, 0, 1 }, - { -1, 0, 1 }, - { -1, 0, 1 } - }; - - /// - /// The vertical gradient operator. - /// - private static readonly Fast2DArray PrewittY = - new float[,] - { - { 1, 1, 1 }, - { 0, 0, 0 }, - { -1, -1, -1 } - }; - - /// - /// Initializes a new instance of the class. - /// - public PrewittProcessor() - : base(PrewittX, PrewittY) - { - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs deleted file mode 100644 index 09aa8ecb6c..0000000000 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; -using System.Diagnostics.CodeAnalysis; -using SixLabors.ImageSharp.Memory; -using SixLabors.ImageSharp.PixelFormats; - -namespace SixLabors.ImageSharp.Processing.Processors -{ - /// - /// The Roberts Cross operator filter. - /// - /// - /// The pixel format. - [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] - internal class RobertsCrossProcessor : EdgeDetector2DProcessor - where TPixel : struct, IPixel - { - /// - /// The horizontal gradient operator. - /// - private static readonly Fast2DArray RobertsCrossX = - new float[,] - { - { 1, 0 }, - { 0, -1 } - }; - - /// - /// The vertical gradient operator. - /// - private static readonly Fast2DArray RobertsCrossY = - new float[,] - { - { 0, 1 }, - { -1, 0 } - }; - - /// - /// Initializes a new instance of the class. - /// - public RobertsCrossProcessor() - : base(RobertsCrossX, RobertsCrossY) - { - } - } -} diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs deleted file mode 100644 index 18f8cbf18c..0000000000 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; -using System.Diagnostics.CodeAnalysis; -using SixLabors.ImageSharp.Memory; -using SixLabors.ImageSharp.PixelFormats; - -namespace SixLabors.ImageSharp.Processing.Processors -{ - /// - /// The Kirsch operator filter. - /// - /// - /// The pixel format. - [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] - internal class RobinsonProcessor : EdgeDetectorCompassProcessor - where TPixel : struct, IPixel - { - /// - /// The North gradient operator - /// - private static readonly Fast2DArray RobinsonNorth = - new float[,] - { - { 1, 2, 1 }, - { 0, 0, 0 }, - { -1, -2, -1 } - }; - - /// - /// The NorthWest gradient operator - /// - private static readonly Fast2DArray RobinsonNorthWest = - new float[,] - { - { 2, 1, 0 }, - { 1, 0, -1 }, - { 0, -1, -2 } - }; - - /// - /// The West gradient operator - /// - private static readonly Fast2DArray RobinsonWest = - new float[,] - { - { 1, 0, -1 }, - { 2, 0, -2 }, - { 1, 0, -1 } - }; - - /// - /// The SouthWest gradient operator - /// - private static readonly Fast2DArray RobinsonSouthWest = - new float[,] - { - { 0, -1, -2 }, - { 1, 0, -1 }, - { 2, 1, 0 } - }; - - /// - /// The South gradient operator - /// - private static readonly Fast2DArray RobinsonSouth = - new float[,] - { - { -1, -2, -1 }, - { 0, 0, 0 }, - { 1, 2, 1 } - }; - - /// - /// The SouthEast gradient operator - /// - private static readonly Fast2DArray RobinsonSouthEast = - new float[,] - { - { -2, -1, 0 }, - { -1, 0, 1 }, - { 0, 1, 2 } - }; - - /// - /// The East gradient operator - /// - private static readonly Fast2DArray RobinsonEast = - new float[,] - { - { -1, 0, 1 }, - { -2, 0, 2 }, - { -1, 0, 1 } - }; - - /// - /// The NorthEast gradient operator - /// - private static readonly Fast2DArray RobinsonNorthEast = - new float[,] - { - { 0, 1, 2 }, - { -1, 0, 1 }, - { -2, -1, 0 } - }; - - /// - public override Fast2DArray North => RobinsonNorth; - - /// - public override Fast2DArray NorthWest => RobinsonNorthWest; - - /// - public override Fast2DArray West => RobinsonWest; - - /// - public override Fast2DArray SouthWest => RobinsonSouthWest; - - /// - public override Fast2DArray South => RobinsonSouth; - - /// - public override Fast2DArray SouthEast => RobinsonSouthEast; - - /// - public override Fast2DArray East => RobinsonEast; - - /// - public override Fast2DArray NorthEast => RobinsonNorthEast; - } -} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/ScharrProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/ScharrProcessor.cs deleted file mode 100644 index e299d3f807..0000000000 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/ScharrProcessor.cs +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; -using System.Diagnostics.CodeAnalysis; -using SixLabors.ImageSharp.Memory; -using SixLabors.ImageSharp.PixelFormats; - -namespace SixLabors.ImageSharp.Processing.Processors -{ - /// - /// The Scharr operator filter. - /// - /// - /// The pixel format. - [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] - internal class ScharrProcessor : EdgeDetector2DProcessor - where TPixel : struct, IPixel - { - /// - /// The horizontal gradient operator. - /// - private static readonly Fast2DArray ScharrX = - new float[,] - { - { -3, 0, 3 }, - { -10, 0, 10 }, - { -3, 0, 3 } - }; - - /// - /// The vertical gradient operator. - /// - private static readonly Fast2DArray ScharrY = - new float[,] - { - { 3, 10, 3 }, - { 0, 0, 0 }, - { -3, -10, -3 } - }; - - /// - /// Initializes a new instance of the class. - /// - public ScharrProcessor() - : base(ScharrX, ScharrY) - { - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/SobelProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/SobelProcessor.cs deleted file mode 100644 index e975e4ff6c..0000000000 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/SobelProcessor.cs +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; -using System.Diagnostics.CodeAnalysis; -using SixLabors.ImageSharp.Memory; -using SixLabors.ImageSharp.PixelFormats; - -namespace SixLabors.ImageSharp.Processing.Processors -{ - /// - /// The Sobel operator filter. - /// - /// - /// The pixel format. - [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] - internal class SobelProcessor : EdgeDetector2DProcessor - where TPixel : struct, IPixel - { - /// - /// The horizontal gradient operator. - /// - private static readonly Fast2DArray SobelX = - new float[,] - { - { -1, 0, 1 }, - { -2, 0, 2 }, - { -1, 0, 1 } - }; - - /// - /// The vertical gradient operator. - /// - private static readonly Fast2DArray SobelY = - new float[,] - { - { -1, -2, -1 }, - { 0, 0, 0 }, - { 1, 2, 1 } - }; - - /// - /// Initializes a new instance of the class. - /// - public SobelProcessor() - : base(SobelX, SobelY) - { - } - } -} diff --git a/src/ImageSharp/Processing/Processors/DelegateProcessor.cs b/src/ImageSharp/Processing/Processors/DelegateProcessor.cs index f17c39681e..2ff00d5833 100644 --- a/src/ImageSharp/Processing/Processors/DelegateProcessor.cs +++ b/src/ImageSharp/Processing/Processors/DelegateProcessor.cs @@ -5,10 +5,10 @@ using System; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing.Processors { /// - /// Allows the application of processors to images. + /// Allows the application of processing algorithms to images via an action delegate /// /// The pixel format. internal class DelegateProcessor : ImageProcessor @@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp.Processing } /// - protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) + protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { // NOP, we did all we wanted to do inside BeforeImageApply } diff --git a/src/ImageSharp/Processing/Processors/Filters/LomographProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/LomographProcessor.cs deleted file mode 100644 index 33c4338d58..0000000000 --- a/src/ImageSharp/Processing/Processors/Filters/LomographProcessor.cs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System.Numerics; - -using SixLabors.ImageSharp.Memory; -using SixLabors.ImageSharp.PixelFormats; -using SixLabors.Primitives; - -namespace SixLabors.ImageSharp.Processing.Processors -{ - /// - /// Converts the colors of the image recreating an old Lomograph effect. - /// - /// The pixel format. - internal class LomographProcessor : FilterProcessor - where TPixel : struct, IPixel - { - private static readonly TPixel VeryDarkGreen = ColorBuilder.FromRGBA(0, 10, 0, 255); - - private readonly MemoryManager memoryManager; - - private readonly GraphicsOptions options; - - /// - /// Initializes a new instance of the class. - /// - /// The to use for buffer allocations. - /// The options effecting blending and composition. - public LomographProcessor(MemoryManager memoryManager, GraphicsOptions options) - : base(MatrixFilters.LomographFilter) - { - this.memoryManager = memoryManager; - this.options = options; - } - - /// - protected override void AfterApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) - { - new VignetteProcessor(this.memoryManager, VeryDarkGreen, this.options).Apply(source, sourceRectangle, configuration); - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Processors/Filters/PolaroidProcessor.cs b/src/ImageSharp/Processing/Processors/Filters/PolaroidProcessor.cs deleted file mode 100644 index 152d586afe..0000000000 --- a/src/ImageSharp/Processing/Processors/Filters/PolaroidProcessor.cs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using SixLabors.ImageSharp.Memory; -using SixLabors.ImageSharp.PixelFormats; -using SixLabors.Primitives; - -namespace SixLabors.ImageSharp.Processing.Processors -{ - /// - /// Converts the colors of the image recreating an old Polaroid effect. - /// - /// The pixel format. - internal class PolaroidProcessor : FilterProcessor - where TPixel : struct, IPixel - { - private static readonly TPixel VeryDarkOrange = ColorBuilder.FromRGB(102, 34, 0); - private static readonly TPixel LightOrange = ColorBuilder.FromRGBA(255, 153, 102, 128); - - private readonly MemoryManager memoryManager; - - private readonly GraphicsOptions options; - - /// - /// Initializes a new instance of the class. - /// - /// The to use for buffer allocations. - /// The options effecting blending and composition. - public PolaroidProcessor(MemoryManager memoryManager, GraphicsOptions options) - : base(MatrixFilters.PolaroidFilter) - { - this.memoryManager = memoryManager; - this.options = options; - } - - /// - protected override void AfterApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) - { - new VignetteProcessor(this.memoryManager, VeryDarkOrange, this.options).Apply(source, sourceRectangle, configuration); - new GlowProcessor(this.memoryManager, LightOrange, source.Width / 4F, this.options).Apply(source, sourceRectangle, configuration); - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/ICloningImageProcessor.cs b/src/ImageSharp/Processing/Processors/ICloningImageProcessor.cs similarity index 83% rename from src/ImageSharp/ICloningImageProcessor.cs rename to src/ImageSharp/Processing/Processors/ICloningImageProcessor.cs index aeb3c815ec..024ccbced1 100644 --- a/src/ImageSharp/ICloningImageProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ICloningImageProcessor.cs @@ -4,7 +4,7 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing.Processors { /// /// Encapsulates methods to alter the pixels of a new image, cloned from the original image. @@ -24,9 +24,9 @@ namespace SixLabors.ImageSharp.Processing /// is null. /// /// - /// doesnt fit the dimension of the image. + /// doesn't fit the dimension of the image. /// - /// Returns the cloned image after thre processor has been applied to it. + /// Returns the cloned image after there processor has been applied to it. Image CloneAndApply(Image source, Rectangle sourceRectangle); } -} +} \ No newline at end of file diff --git a/src/ImageSharp/IImageProcessor.cs b/src/ImageSharp/Processing/Processors/IImageProcessor.cs similarity index 88% rename from src/ImageSharp/IImageProcessor.cs rename to src/ImageSharp/Processing/Processors/IImageProcessor.cs index bd6df8d835..d7fe0465be 100644 --- a/src/ImageSharp/IImageProcessor.cs +++ b/src/ImageSharp/Processing/Processors/IImageProcessor.cs @@ -4,7 +4,7 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Processors { /// /// Encapsulates methods to alter the pixels of an image. @@ -24,8 +24,8 @@ namespace SixLabors.ImageSharp /// is null. /// /// - /// doesnt fit the dimension of the image. + /// doesn't fit the dimension of the image. /// void Apply(Image source, Rectangle sourceRectangle); } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Processors/ImageProcessor.cs b/src/ImageSharp/Processing/Processors/ImageProcessor.cs index cab99112c1..0d27a9e1e8 100644 --- a/src/ImageSharp/Processing/Processors/ImageProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ImageProcessor.cs @@ -6,7 +6,7 @@ using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing.Processors { /// /// Allows the application of processors to images. @@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp.Processing #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); + throw new ImageProcessingException($"An error occurred when processing the image using {this.GetType().Name}. See the inner exception for more detail.", ex); #endif } } @@ -52,9 +52,9 @@ namespace SixLabors.ImageSharp.Processing { try { - this.BeforeApply(source, sourceRectangle, configuration); - this.OnApply(source, sourceRectangle, configuration); - this.AfterApply(source, sourceRectangle, configuration); + this.BeforeFrameApply(source, sourceRectangle, configuration); + this.OnFrameApply(source, sourceRectangle, configuration); + this.AfterFrameApply(source, sourceRectangle, configuration); } #if DEBUG catch (Exception) @@ -63,7 +63,7 @@ namespace SixLabors.ImageSharp.Processing #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); + throw new ImageProcessingException($"An error occurred when processing the image using {this.GetType().Name}. See the inner exception for more detail.", ex); #endif } } @@ -83,7 +83,7 @@ namespace SixLabors.ImageSharp.Processing /// The source image. Cannot be null. /// The structure that specifies the portion of the image object to draw. /// The configuration. - protected virtual void BeforeApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) + protected virtual void BeforeFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { } @@ -94,7 +94,7 @@ namespace SixLabors.ImageSharp.Processing /// The source image. Cannot be null. /// The structure that specifies the portion of the image object to draw. /// The configuration. - protected abstract void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration); + protected abstract void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration); /// /// This method is called after the process is applied to prepare the processor. @@ -102,7 +102,7 @@ namespace SixLabors.ImageSharp.Processing /// The source image. Cannot be null. /// The structure that specifies the portion of the image object to draw. /// The configuration. - protected virtual void AfterApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) + protected virtual void AfterFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { } diff --git a/src/ImageSharp/Processing/Processors/Transforms/CropProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/CropProcessor.cs deleted file mode 100644 index c04014ae35..0000000000 --- a/src/ImageSharp/Processing/Processors/Transforms/CropProcessor.cs +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; -using System.Threading.Tasks; -using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Memory; -using SixLabors.ImageSharp.PixelFormats; -using SixLabors.Primitives; - -// TODO: Convert this into a cloning processor inheriting TransformProcessor once Anton's memory PR is merged -namespace SixLabors.ImageSharp.Processing.Processors -{ - /// - /// Provides methods to allow the cropping of an image. - /// - /// The pixel format. - internal class CropProcessor : ImageProcessor - where TPixel : struct, IPixel - { - /// - /// Initializes a new instance of the class. - /// - /// The target cropped rectangle. - public CropProcessor(Rectangle cropRectangle) - { - this.CropRectangle = cropRectangle; - } - - /// - /// Gets the width. - /// - public Rectangle CropRectangle { get; } - - /// - protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) - { - if (this.CropRectangle == sourceRectangle) - { - return; - } - - int minY = Math.Max(this.CropRectangle.Y, sourceRectangle.Y); - int maxY = Math.Min(this.CropRectangle.Bottom, sourceRectangle.Bottom); - int minX = Math.Max(this.CropRectangle.X, sourceRectangle.X); - int maxX = Math.Min(this.CropRectangle.Right, sourceRectangle.Right); - - using (Buffer2D targetPixels = configuration.MemoryManager.Allocate2D(this.CropRectangle.Size)) - { - Parallel.For( - minY, - maxY, - configuration.ParallelOptions, - y => - { - Span sourceRow = source.GetPixelRowSpan(y).Slice(minX); - Span targetRow = targetPixels.GetRowSpan(y - minY); - SpanHelper.Copy(sourceRow, targetRow, maxX - minX); - }); - - Buffer2D.SwapContents(source.PixelBuffer, targetPixels); - } - } - - /// - protected override void AfterImageApply(Image source, Rectangle sourceRectangle) - => TransformHelpers.UpdateDimensionalMetData(source); - } -} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor.cs deleted file mode 100644 index d2a08daba6..0000000000 --- a/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor.cs +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; -using SixLabors.ImageSharp.PixelFormats; -using SixLabors.Primitives; - -namespace SixLabors.ImageSharp.Processing.Processors -{ - /// - /// Provides methods to allow the cropping of an image to preserve areas of highest - /// entropy. - /// - /// The pixel format. - internal class EntropyCropProcessor : ImageProcessor - where TPixel : struct, IPixel - { - /// - /// Initializes a new instance of the class. - /// - /// The threshold to split the image. Must be between 0 and 1. - /// - /// is less than 0 or is greater than 1. - /// - public EntropyCropProcessor(float threshold) - { - Guard.MustBeBetweenOrEqualTo(threshold, 0, 1, nameof(threshold)); - this.Threshold = threshold; - } - - /// - /// Gets the threshold value. - /// - public float Threshold { get; } - - /// - protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) - { - using (ImageFrame temp = source.Clone()) - { - // Detect the edges. - new SobelProcessor().Apply(temp, sourceRectangle, configuration); - - // Apply threshold binarization filter. - new BinaryThresholdProcessor(this.Threshold).Apply(temp, sourceRectangle, configuration); - - // Search for the first white pixels - Rectangle rectangle = ImageMaths.GetFilteredBoundingRectangle(temp, 0); - - if (rectangle == sourceRectangle) - { - return; - } - - new CropProcessor(rectangle).Apply(source, sourceRectangle, configuration); - } - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/Quantizers/Box.cs b/src/ImageSharp/Processing/Quantization/Box.cs similarity index 96% rename from src/ImageSharp/Quantizers/Box.cs rename to src/ImageSharp/Processing/Quantization/Box.cs index cd1936b653..e6e1166f88 100644 --- a/src/ImageSharp/Quantizers/Box.cs +++ b/src/ImageSharp/Processing/Quantization/Box.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Quantizers +namespace SixLabors.ImageSharp.Processing.Quantization { /// /// Represents a box color cube. diff --git a/src/ImageSharp/Quantizers/IQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Quantization/IQuantizer{TPixel}.cs similarity index 88% rename from src/ImageSharp/Quantizers/IQuantizer{TPixel}.cs rename to src/ImageSharp/Processing/Quantization/IQuantizer{TPixel}.cs index 82f6146a3e..841b84496b 100644 --- a/src/ImageSharp/Quantizers/IQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Quantization/IQuantizer{TPixel}.cs @@ -1,10 +1,10 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Dithering; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion; -namespace SixLabors.ImageSharp.Quantizers +namespace SixLabors.ImageSharp.Processing.Quantization { /// /// Provides methods for for allowing quantization of images pixels with configurable dithering. @@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Quantizers /// /// A representing a quantized version of the image pixels. /// - QuantizedImage Quantize(ImageFrame image, int maxColors); + QuantizedFrame Quantize(ImageFrame image, int maxColors); } /// @@ -39,4 +39,4 @@ namespace SixLabors.ImageSharp.Quantizers /// IErrorDiffuser DitherType { get; set; } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Quantizers/OctreeQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Quantization/OctreeQuantizer{TPixel}.cs similarity index 91% rename from src/ImageSharp/Quantizers/OctreeQuantizer{TPixel}.cs rename to src/ImageSharp/Processing/Quantization/OctreeQuantizer{TPixel}.cs index 8b8db61777..5d81049371 100644 --- a/src/ImageSharp/Quantizers/OctreeQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Quantization/OctreeQuantizer{TPixel}.cs @@ -4,11 +4,11 @@ using System; using System.Collections.Generic; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Quantizers.Base; -namespace SixLabors.ImageSharp.Quantizers +namespace SixLabors.ImageSharp.Processing.Quantization { /// /// Encapsulates methods to calculate the color palette if an image using an Octree pattern. @@ -56,7 +56,7 @@ namespace SixLabors.ImageSharp.Quantizers } /// - public override QuantizedImage Quantize(ImageFrame image, int maxColors) + public override QuantizedFrame Quantize(ImageFrame image, int maxColors) { this.colors = (byte)maxColors.Clamp(1, 255); this.octree = new Octree(this.GetBitsNeededForColorDepth(this.colors)); @@ -66,6 +66,28 @@ namespace SixLabors.ImageSharp.Quantizers return base.Quantize(image, this.colors); } + /// + protected override void FirstPass(ImageFrame source, int width, int height) + { + // Loop through each row + for (int y = 0; y < height; y++) + { + Span row = source.GetPixelRowSpan(y); + ref TPixel scanBaseRef = ref MemoryMarshal.GetReference(row); + + // And loop through each column + var rgba = default(Rgba32); + for (int x = 0; x < width; x++) + { + ref TPixel pixel = ref Unsafe.Add(ref scanBaseRef, x); + pixel.ToRgba32(ref rgba); + + // Add the color to the Octree + this.octree.AddColor(ref pixel, ref rgba); + } + } + } + /// protected override void SecondPass(ImageFrame source, byte[] output, int width, int height) { @@ -115,14 +137,6 @@ namespace SixLabors.ImageSharp.Quantizers } } - /// - protected override void InitialQuantizePixel(TPixel pixel) - { - // Add the color to the Octree - var rgba = default(Rgba32); - this.octree.AddColor(pixel, ref rgba); - } - /// protected override TPixel[] GetPalette() { @@ -173,7 +187,7 @@ namespace SixLabors.ImageSharp.Quantizers { if (this.Dither) { - // The colors have changed so we need to use Euclidean distance caclulation to find the closest value. + // The colors have changed so we need to use Euclidean distance calculation to find the closest value. // This palette can never be null here. return this.GetClosestPixel(pixel, this.palette, this.colorMap); } @@ -184,7 +198,7 @@ namespace SixLabors.ImageSharp.Quantizers return this.transparentIndex; } - return (byte)this.octree.GetPaletteIndex(pixel, ref rgba); + return (byte)this.octree.GetPaletteIndex(ref pixel, ref rgba); } /// @@ -268,7 +282,7 @@ namespace SixLabors.ImageSharp.Quantizers /// /// The pixel data. /// The color. - public void AddColor(TPixel pixel, ref Rgba32 rgba) + public void AddColor(ref TPixel pixel, ref Rgba32 rgba) { // Check if this request is for the same color as the last if (this.previousColor.Equals(pixel)) @@ -278,18 +292,18 @@ namespace SixLabors.ImageSharp.Quantizers if (this.previousNode == null) { this.previousColor = pixel; - this.root.AddColor(pixel, this.maxColorBits, 0, this, ref rgba); + this.root.AddColor(ref pixel, this.maxColorBits, 0, this, ref rgba); } else { // Just update the previous node - this.previousNode.Increment(pixel, ref rgba); + this.previousNode.Increment(ref pixel, ref rgba); } } else { this.previousColor = pixel; - this.root.AddColor(pixel, this.maxColorBits, 0, this, ref rgba); + this.root.AddColor(ref pixel, this.maxColorBits, 0, this, ref rgba); } } @@ -325,9 +339,9 @@ namespace SixLabors.ImageSharp.Quantizers /// /// The . /// - public int GetPaletteIndex(TPixel pixel, ref Rgba32 rgba) + public int GetPaletteIndex(ref TPixel pixel, ref Rgba32 rgba) { - return this.root.GetPaletteIndex(pixel, 0, ref rgba); + return this.root.GetPaletteIndex(ref pixel, 0, ref rgba); } /// @@ -454,12 +468,12 @@ namespace SixLabors.ImageSharp.Quantizers /// The level in the tree /// The tree to which this node belongs /// The color to map to. - public void AddColor(TPixel pixel, int colorBits, int level, Octree octree, ref Rgba32 rgba) + public void AddColor(ref TPixel pixel, int colorBits, int level, Octree octree, ref Rgba32 rgba) { // Update the color information if this is a leaf if (this.leaf) { - this.Increment(pixel, ref rgba); + this.Increment(ref pixel, ref rgba); // Setup the previous node octree.TrackPrevious(this); @@ -484,7 +498,7 @@ namespace SixLabors.ImageSharp.Quantizers } // Add the color to the child node - child.AddColor(pixel, colorBits, level + 1, octree, ref rgba); + child.AddColor(ref pixel, colorBits, level + 1, octree, ref rgba); } } @@ -562,7 +576,7 @@ namespace SixLabors.ImageSharp.Quantizers /// /// The representing the index of the pixel in the palette. /// - public int GetPaletteIndex(TPixel pixel, int level, ref Rgba32 rgba) + public int GetPaletteIndex(ref TPixel pixel, int level, ref Rgba32 rgba) { int index = this.paletteIndex; @@ -577,7 +591,7 @@ namespace SixLabors.ImageSharp.Quantizers if (this.children[pixelIndex] != null) { - index = this.children[pixelIndex].GetPaletteIndex(pixel, level + 1, ref rgba); + index = this.children[pixelIndex].GetPaletteIndex(ref pixel, level + 1, ref rgba); } else { @@ -593,7 +607,7 @@ namespace SixLabors.ImageSharp.Quantizers /// /// The pixel to add. /// The color to map to. - public void Increment(TPixel pixel, ref Rgba32 rgba) + public void Increment(ref TPixel pixel, ref Rgba32 rgba) { pixel.ToRgba32(ref rgba); this.pixelCount++; diff --git a/src/ImageSharp/Quantizers/PaletteQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Quantization/PaletteQuantizer{TPixel}.cs similarity index 96% rename from src/ImageSharp/Quantizers/PaletteQuantizer{TPixel}.cs rename to src/ImageSharp/Processing/Quantization/PaletteQuantizer{TPixel}.cs index cd1b4b07b1..8955e14dd4 100644 --- a/src/ImageSharp/Quantizers/PaletteQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Quantization/PaletteQuantizer{TPixel}.cs @@ -6,9 +6,8 @@ using System.Collections.Generic; using System.Runtime.CompilerServices; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Quantizers.Base; -namespace SixLabors.ImageSharp.Quantizers +namespace SixLabors.ImageSharp.Processing.Quantization { /// /// Encapsulates methods to create a quantized image based upon the given palette. @@ -49,7 +48,7 @@ namespace SixLabors.ImageSharp.Quantizers } /// - public override QuantizedImage Quantize(ImageFrame image, int maxColors) + public override QuantizedFrame Quantize(ImageFrame image, int maxColors) { Array.Resize(ref this.colors, maxColors.Clamp(1, 255)); this.colorMap.Clear(); diff --git a/src/ImageSharp/Processing/Quantization/Processors/QuantizeProcessor.cs b/src/ImageSharp/Processing/Quantization/Processors/QuantizeProcessor.cs new file mode 100644 index 0000000000..e6b1099937 --- /dev/null +++ b/src/ImageSharp/Processing/Quantization/Processors/QuantizeProcessor.cs @@ -0,0 +1,72 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Threading.Tasks; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; + +namespace SixLabors.ImageSharp.Processing.Quantization.Processors +{ + /// + /// Enables the quantization of images to remove the number of colors used in the image palette. + /// + /// The pixel format. + internal class QuantizeProcessor : ImageProcessor + where TPixel : struct, IPixel + { + /// + /// Initializes a new instance of the class. + /// + /// The quantizer used to reduce the color palette + /// The maximum number of colors to reduce the palette to + public QuantizeProcessor(IQuantizer quantizer, int maxColors) + { + Guard.NotNull(quantizer, nameof(quantizer)); + Guard.MustBeGreaterThan(maxColors, 0, nameof(maxColors)); + + this.Quantizer = quantizer; + this.MaxColors = maxColors; + } + + /// + /// Gets the quantizer + /// + public IQuantizer Quantizer { get; } + + /// + /// Gets the maximum number of palette colors + /// + public int MaxColors { get; } + + /// + protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) + { + QuantizedFrame quantized = this.Quantizer.Quantize(source, this.MaxColors); + int paletteCount = quantized.Palette.Length - 1; + + using (Buffer2D pixels = source.MemoryManager.Allocate2D(quantized.Width, quantized.Height)) + { + Parallel.For( + 0, + pixels.Height, + configuration.ParallelOptions, + y => + { + Span row = pixels.GetRowSpan(y); + int yy = y * pixels.Width; + for (int x = 0; x < pixels.Width; x++) + { + int i = x + yy; + TPixel color = quantized.Palette[Math.Min(paletteCount, quantized.Pixels[i])]; + row[x] = color; + } + }); + + Buffer2D.SwapContents(source.PixelBuffer, pixels); + } + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Quantizers/Quantization.cs b/src/ImageSharp/Processing/Quantization/QuantizationMode.cs similarity index 90% rename from src/ImageSharp/Quantizers/Quantization.cs rename to src/ImageSharp/Processing/Quantization/QuantizationMode.cs index df55d3e87a..69857b3844 100644 --- a/src/ImageSharp/Quantizers/Quantization.cs +++ b/src/ImageSharp/Processing/Quantization/QuantizationMode.cs @@ -1,12 +1,12 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Quantization { /// /// Provides enumeration over how an image should be quantized. /// - public enum Quantization + public enum QuantizationMode { /// /// An adaptive Octree quantizer. Fast with good quality. diff --git a/src/ImageSharp/Quantizers/Quantize.cs b/src/ImageSharp/Processing/Quantization/QuantizeExtensions.cs similarity index 53% rename from src/ImageSharp/Quantizers/Quantize.cs rename to src/ImageSharp/Processing/Quantization/QuantizeExtensions.cs index f2a09abb77..2b367ffe95 100644 --- a/src/ImageSharp/Quantizers/Quantize.cs +++ b/src/ImageSharp/Processing/Quantization/QuantizeExtensions.cs @@ -1,19 +1,15 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; -using System.Threading.Tasks; -using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Quantizers; +using SixLabors.ImageSharp.Processing.Quantization.Processors; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Quantization { /// - /// Extension methods for the type. + /// Adds extensions that allow the application of quantizing algorithms to the type. /// - public static partial class ImageExtensions + public static class QuantizeExtensions { /// /// Applies quantization to the image. @@ -23,17 +19,17 @@ namespace SixLabors.ImageSharp /// The quantization mode to apply to perform the operation. /// The maximum number of colors to return. Defaults to 256. /// The . - public static IImageProcessingContext Quantize(this IImageProcessingContext source, Quantization mode = Quantization.Octree, int maxColors = 256) + public static IImageProcessingContext Quantize(this IImageProcessingContext source, QuantizationMode mode = QuantizationMode.Octree, int maxColors = 256) where TPixel : struct, IPixel { IQuantizer quantizer; switch (mode) { - case Quantization.Wu: + case QuantizationMode.Wu: quantizer = new WuQuantizer(); break; - case Quantization.Palette: + case QuantizationMode.Palette: quantizer = new PaletteQuantizer(); break; @@ -55,34 +51,6 @@ namespace SixLabors.ImageSharp /// The . public static IImageProcessingContext Quantize(this IImageProcessingContext source, IQuantizer quantizer, int maxColors) where TPixel : struct, IPixel - { - return source.Apply(img => - { - // TODO : move helper logic into the processor - QuantizedImage quantized = quantizer.Quantize(img.Frames.RootFrame, maxColors); - int palleteCount = quantized.Palette.Length - 1; - - using (Buffer2D pixels = source.MemoryManager.Allocate2D(quantized.Width, quantized.Height)) - { - Parallel.For( - 0, - pixels.Height, - img.GetConfiguration().ParallelOptions, - y => - { - Span row = pixels.GetRowSpan(y); - int yy = y * pixels.Width; - for (int x = 0; x < pixels.Width; x++) - { - int i = x + yy; - TPixel color = quantized.Palette[Math.Min(palleteCount, quantized.Pixels[i])]; - row[x] = color; - } - }); - - Buffer2D.SwapContents(img.Frames[0].PixelBuffer, pixels); - } - }); - } + => source.ApplyProcessor(new QuantizeProcessor(quantizer, maxColors)); } } \ No newline at end of file diff --git a/src/ImageSharp/Quantizers/QuantizedImage{TPixel}.cs b/src/ImageSharp/Processing/Quantization/QuantizedFrame{TPixel}.cs similarity index 73% rename from src/ImageSharp/Quantizers/QuantizedImage{TPixel}.cs rename to src/ImageSharp/Processing/Quantization/QuantizedFrame{TPixel}.cs index 52cf1a8d9a..ac87e1c7c5 100644 --- a/src/ImageSharp/Quantizers/QuantizedImage{TPixel}.cs +++ b/src/ImageSharp/Processing/Quantization/QuantizedFrame{TPixel}.cs @@ -4,23 +4,23 @@ using System; using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Quantizers +namespace SixLabors.ImageSharp.Processing.Quantization { /// - /// Represents a quantized image where the pixels indexed by a color palette. + /// Represents a quantized image frame where the pixels indexed by a color palette. /// /// The pixel format. - public class QuantizedImage + public class QuantizedFrame where TPixel : struct, IPixel { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The image width. /// The image height. /// The color palette. /// The quantized pixels. - public QuantizedImage(int width, int height, TPixel[] palette, byte[] pixels) + public QuantizedFrame(int width, int height, TPixel[] palette, byte[] pixels) { Guard.MustBeGreaterThan(width, 0, nameof(width)); Guard.MustBeGreaterThan(height, 0, nameof(height)); @@ -39,22 +39,22 @@ namespace SixLabors.ImageSharp.Quantizers } /// - /// Gets the width of this . + /// Gets the width of this . /// public int Width { get; } /// - /// Gets the height of this . + /// Gets the height of this . /// public int Height { get; } /// - /// Gets the color palette of this . + /// Gets the color palette of this . /// public TPixel[] Palette { get; } /// - /// Gets the pixels of this . + /// Gets the pixels of this . /// public byte[] Pixels { get; } } diff --git a/src/ImageSharp/Quantizers/QuantizerBase{TPixel}.cs b/src/ImageSharp/Processing/Quantization/QuantizerBase{TPixel}.cs similarity index 78% rename from src/ImageSharp/Quantizers/QuantizerBase{TPixel}.cs rename to src/ImageSharp/Processing/Quantization/QuantizerBase{TPixel}.cs index 0b41edf98d..96763195d2 100644 --- a/src/ImageSharp/Quantizers/QuantizerBase{TPixel}.cs +++ b/src/ImageSharp/Processing/Quantization/QuantizerBase{TPixel}.cs @@ -5,11 +5,11 @@ using System; using System.Collections.Generic; using System.Numerics; using System.Runtime.CompilerServices; -using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Dithering; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Dithering; +using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion; -namespace SixLabors.ImageSharp.Quantizers.Base +namespace SixLabors.ImageSharp.Processing.Quantization { /// /// Encapsulates methods to calculate the color palette of an image. @@ -43,10 +43,10 @@ namespace SixLabors.ImageSharp.Quantizers.Base public bool Dither { get; set; } = true; /// - public IErrorDiffuser DitherType { get; set; } = KnownDiffusers.FloydSteinberg; + public IErrorDiffuser DitherType { get; set; } = DiffuseMode.FloydSteinberg; /// - public virtual QuantizedImage Quantize(ImageFrame image, int maxColors) + public virtual QuantizedFrame Quantize(ImageFrame image, int maxColors) { Guard.NotNull(image, nameof(image)); @@ -79,7 +79,7 @@ namespace SixLabors.ImageSharp.Quantizers.Base this.SecondPass(image, quantizedPixels, width, height); } - return new QuantizedImage(width, height, colorPalette, quantizedPixels); + return new QuantizedFrame(width, height, colorPalette, quantizedPixels); } /// @@ -90,22 +90,10 @@ namespace SixLabors.ImageSharp.Quantizers.Base /// The height in pixels of the image. protected virtual void FirstPass(ImageFrame source, int width, int height) { - // Loop through each row - for (int y = 0; y < height; y++) - { - Span row = source.GetPixelRowSpan(y); - - // And loop through each column - for (int x = 0; x < width; x++) - { - // Now I have the pixel, call the FirstPassQuantize function... - this.InitialQuantizePixel(row[x]); - } - } } /// - /// Execute a second pass through the bitmap + /// Execute a second pass through the image /// /// The source image. /// The output pixel array @@ -114,20 +102,8 @@ namespace SixLabors.ImageSharp.Quantizers.Base protected abstract void SecondPass(ImageFrame source, byte[] output, int width, int height); /// - /// Override this to process the pixel in the first pass of the algorithm - /// TODO: We really should do this on a per-row basis! Shouldn't we internalize this method? - /// - /// The pixel to quantize - /// - /// This function need only be overridden if your quantize algorithm needs two passes, - /// such as an Octree quantizer. - /// - protected virtual void InitialQuantizePixel(TPixel pixel) - { - } - - /// - /// Retrieve the palette for the quantized image. Can be called more than once so make sure calls are cached. + /// Retrieve the palette for the quantized image. + /// Can be called more than once so make sure calls are cached. /// /// /// diff --git a/src/ImageSharp/Quantizers/WuQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Quantization/WuQuantizer{TPixel}.cs similarity index 98% rename from src/ImageSharp/Quantizers/WuQuantizer{TPixel}.cs rename to src/ImageSharp/Processing/Quantization/WuQuantizer{TPixel}.cs index 0aadf49732..0c2371cf39 100644 --- a/src/ImageSharp/Quantizers/WuQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Quantization/WuQuantizer{TPixel}.cs @@ -2,16 +2,15 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Buffers; using System.Collections.Generic; using System.Numerics; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Quantizers.Base; -namespace SixLabors.ImageSharp.Quantizers +namespace SixLabors.ImageSharp.Processing.Quantization { /// /// An implementation of Wu's color quantizer with alpha channel. @@ -137,7 +136,7 @@ namespace SixLabors.ImageSharp.Quantizers } /// - public override QuantizedImage Quantize(ImageFrame image, int maxColors) + public override QuantizedFrame Quantize(ImageFrame image, int maxColors) { Guard.NotNull(image, nameof(image)); @@ -199,14 +198,13 @@ namespace SixLabors.ImageSharp.Quantizers return this.palette; } - /// - protected override void InitialQuantizePixel(TPixel pixel) + /// + /// Quantizes the pixel + /// + /// The rgba used to quantize the pixel input + private void QuantizePixel(ref Rgba32 rgba) { // Add the color to a 3-D color histogram. - // Colors are expected in r->g->b->a format - var rgba = default(Rgba32); - pixel.ToRgba32(ref rgba); - int r = rgba.R >> (8 - IndexBits); int g = rgba.G >> (8 - IndexBits); int b = rgba.B >> (8 - IndexBits); @@ -238,11 +236,16 @@ namespace SixLabors.ImageSharp.Quantizers // Loop through each row for (int y = 0; y < height; y++) { + Span row = source.GetPixelRowSpan(y); + ref TPixel scanBaseRef = ref MemoryMarshal.GetReference(row); + // And loop through each column + var rgba = default(Rgba32); for (int x = 0; x < width; x++) { - // Now I have the pixel, call the FirstPassQuantize function... - this.InitialQuantizePixel(source[x, y]); + ref TPixel pixel = ref Unsafe.Add(ref scanBaseRef, x); + pixel.ToRgba32(ref rgba); + this.QuantizePixel(ref rgba); } } diff --git a/src/ImageSharp/Processing/Transforms/Options/AnchorPosition.cs b/src/ImageSharp/Processing/Transforms/AnchorPosition.cs similarity index 96% rename from src/ImageSharp/Processing/Transforms/Options/AnchorPosition.cs rename to src/ImageSharp/Processing/Transforms/AnchorPosition.cs index 263af14ccd..4519f90f94 100644 --- a/src/ImageSharp/Processing/Transforms/Options/AnchorPosition.cs +++ b/src/ImageSharp/Processing/Transforms/AnchorPosition.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing.Transforms { /// /// Enumerated anchor positions to apply to resized images. diff --git a/src/ImageSharp/Processing/Transforms/AutoOrient.cs b/src/ImageSharp/Processing/Transforms/AutoOrientExtensions.cs similarity index 74% rename from src/ImageSharp/Processing/Transforms/AutoOrient.cs rename to src/ImageSharp/Processing/Transforms/AutoOrientExtensions.cs index b8b31ff278..d3ac16708a 100644 --- a/src/ImageSharp/Processing/Transforms/AutoOrient.cs +++ b/src/ImageSharp/Processing/Transforms/AutoOrientExtensions.cs @@ -2,14 +2,14 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Transforms.Processors; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Transforms { /// - /// Extension methods for the type. + /// Adds extensions that allow the application of auto-orientation operations to the type. /// - public static partial class ImageExtensions + public static class AutoOrientExtensions { /// /// Adjusts an image so that its orientation is suitable for viewing. Adjustments are based on EXIF metadata embedded in the image. diff --git a/src/ImageSharp/Processing/Transforms/Crop.cs b/src/ImageSharp/Processing/Transforms/CropExtensions.cs similarity index 78% rename from src/ImageSharp/Processing/Transforms/Crop.cs rename to src/ImageSharp/Processing/Transforms/CropExtensions.cs index 3fa59c2483..9e347f51cb 100644 --- a/src/ImageSharp/Processing/Transforms/Crop.cs +++ b/src/ImageSharp/Processing/Transforms/CropExtensions.cs @@ -1,17 +1,16 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Transforms.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Transforms { /// - /// Extension methods for the type. + /// Adds extensions that allow the application of cropping operations to the type. /// - public static partial class ImageExtensions + public static class CropExtensions { /// /// Crops an image to the given width and height. @@ -23,7 +22,7 @@ namespace SixLabors.ImageSharp /// The public static IImageProcessingContext Crop(this IImageProcessingContext source, int width, int height) where TPixel : struct, IPixel - => Crop(source, new Rectangle(0, 0, width, height)); + => Crop(source, new Rectangle(0, 0, width, height)); /// /// Crops an image to the given rectangle. @@ -36,6 +35,6 @@ namespace SixLabors.ImageSharp /// The public static IImageProcessingContext Crop(this IImageProcessingContext source, Rectangle cropRectangle) where TPixel : struct, IPixel - => source.ApplyProcessor(new CropProcessor(cropRectangle)); + => source.ApplyProcessor(new CropProcessor(cropRectangle)); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/EntropyCrop.cs b/src/ImageSharp/Processing/Transforms/EntropyCrop.cs deleted file mode 100644 index cbd2b46599..0000000000 --- a/src/ImageSharp/Processing/Transforms/EntropyCrop.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; -using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; - -namespace SixLabors.ImageSharp -{ - /// - /// Extension methods for the type. - /// - public static partial class ImageExtensions - { - /// - /// Crops an image to the area of greatest entropy. - /// - /// The pixel format. - /// The image to crop. - /// The threshold for entropic density. - /// The - public static IImageProcessingContext EntropyCrop(this IImageProcessingContext source, float threshold = .5f) - where TPixel : struct, IPixel - => source.ApplyProcessor(new EntropyCropProcessor(threshold)); - } -} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/EntropyCropExtensions.cs b/src/ImageSharp/Processing/Transforms/EntropyCropExtensions.cs new file mode 100644 index 0000000000..3ca4c72bc1 --- /dev/null +++ b/src/ImageSharp/Processing/Transforms/EntropyCropExtensions.cs @@ -0,0 +1,35 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Transforms.Processors; + +namespace SixLabors.ImageSharp.Processing.Transforms +{ + /// + /// Adds extensions that allow the application of entropy cropping operations to the type. + /// + public static class EntropyCropExtensions + { + /// + /// Crops an image to the area of greatest entropy using a threshold for entropic density of .5F. + /// + /// The pixel format. + /// The image to crop. + /// The + public static IImageProcessingContext EntropyCrop(this IImageProcessingContext source) + where TPixel : struct, IPixel + => source.ApplyProcessor(new EntropyCropProcessor()); + + /// + /// Crops an image to the area of greatest entropy. + /// + /// The pixel format. + /// The image to crop. + /// The threshold for entropic density. + /// The + public static IImageProcessingContext EntropyCrop(this IImageProcessingContext source, float threshold) + where TPixel : struct, IPixel + => source.ApplyProcessor(new EntropyCropProcessor(threshold)); + } +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/Flip.cs b/src/ImageSharp/Processing/Transforms/FlipExtensions.cs similarity index 69% rename from src/ImageSharp/Processing/Transforms/Flip.cs rename to src/ImageSharp/Processing/Transforms/FlipExtensions.cs index e153e89f28..e88074c137 100644 --- a/src/ImageSharp/Processing/Transforms/Flip.cs +++ b/src/ImageSharp/Processing/Transforms/FlipExtensions.cs @@ -1,17 +1,15 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Transforms.Processors; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Transforms { /// - /// Extension methods for the type. + /// Adds extensions that allow the application of flipping operations to the type. /// - public static partial class ImageExtensions + public static class FlipExtensions { /// /// Flips an image by the given instructions. @@ -22,6 +20,6 @@ namespace SixLabors.ImageSharp /// The public static IImageProcessingContext Flip(this IImageProcessingContext source, FlipType flipType) where TPixel : struct, IPixel - => source.ApplyProcessor(new FlipProcessor(flipType)); + => source.ApplyProcessor(new FlipProcessor(flipType)); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/Options/FlipType.cs b/src/ImageSharp/Processing/Transforms/FlipType.cs similarity index 90% rename from src/ImageSharp/Processing/Transforms/Options/FlipType.cs rename to src/ImageSharp/Processing/Transforms/FlipType.cs index 0129891f66..71a4e6fc8f 100644 --- a/src/ImageSharp/Processing/Transforms/Options/FlipType.cs +++ b/src/ImageSharp/Processing/Transforms/FlipType.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing.Transforms { /// /// Provides enumeration over how a image should be flipped. @@ -23,4 +23,4 @@ namespace SixLabors.ImageSharp.Processing /// Vertical, } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/Options/Orientation.cs b/src/ImageSharp/Processing/Transforms/OrientationType.cs similarity index 93% rename from src/ImageSharp/Processing/Transforms/Options/Orientation.cs rename to src/ImageSharp/Processing/Transforms/OrientationType.cs index 9c8d96a71c..752ac9fe68 100644 --- a/src/ImageSharp/Processing/Transforms/Options/Orientation.cs +++ b/src/ImageSharp/Processing/Transforms/OrientationType.cs @@ -1,12 +1,12 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing.Transforms { /// /// Enumerates the available orientation values supplied by EXIF metadata. /// - internal enum Orientation : ushort + internal enum OrientationType : ushort { /// /// Unknown rotation. diff --git a/src/ImageSharp/Processing/Transforms/Pad.cs b/src/ImageSharp/Processing/Transforms/PadExtensions.cs similarity index 76% rename from src/ImageSharp/Processing/Transforms/Pad.cs rename to src/ImageSharp/Processing/Transforms/PadExtensions.cs index 2f637aa162..23e9d5d27e 100644 --- a/src/ImageSharp/Processing/Transforms/Pad.cs +++ b/src/ImageSharp/Processing/Transforms/PadExtensions.cs @@ -2,15 +2,14 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing; using SixLabors.Primitives; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Transforms { /// - /// Extension methods for the type. + /// Adds extensions that allow the application of padding operations to the type. /// - public static partial class ImageExtensions + public static class PadExtensions { /// /// Evenly pads an image to fit the new dimensions. @@ -27,10 +26,10 @@ namespace SixLabors.ImageSharp { Size = new Size(width, height), Mode = ResizeMode.BoxPad, - Sampler = KnownResamplers.NearestNeighbor + Sampler = ResampleMode.NearestNeighbor }; - return Resize(source, options); + return source.Resize(options); } } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor.cs b/src/ImageSharp/Processing/Transforms/Processors/AffineTransformProcessor.cs similarity index 97% rename from src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor.cs rename to src/ImageSharp/Processing/Transforms/Processors/AffineTransformProcessor.cs index ac11e0dfb3..b9f3dc4bf5 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor.cs +++ b/src/ImageSharp/Processing/Transforms/Processors/AffineTransformProcessor.cs @@ -7,12 +7,12 @@ using System.Linq; using System.Numerics; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Helpers; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Transforms.Resamplers; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Transforms.Processors { /// /// Provides the base methods to perform affine transforms on an image. @@ -56,7 +56,7 @@ namespace SixLabors.ImageSharp.Processing.Processors } /// - protected override void OnApply( + protected override void OnFrameApply( ImageFrame source, ImageFrame destination, Rectangle sourceRectangle, @@ -208,8 +208,6 @@ namespace SixLabors.ImageSharp.Processing.Processors /// The . /// protected virtual Matrix3x2 GetProcessingMatrix(Rectangle sourceRectangle, Rectangle destinationRectangle) - { - return this.TransformMatrix; - } + => this.TransformMatrix; } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Processors/Transforms/AutoOrientProcessor.cs b/src/ImageSharp/Processing/Transforms/Processors/AutoOrientProcessor.cs similarity index 69% rename from src/ImageSharp/Processing/Processors/Transforms/AutoOrientProcessor.cs rename to src/ImageSharp/Processing/Transforms/Processors/AutoOrientProcessor.cs index 7f811eebc1..fdb58918af 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/AutoOrientProcessor.cs +++ b/src/ImageSharp/Processing/Transforms/Processors/AutoOrientProcessor.cs @@ -4,9 +4,10 @@ using System; using SixLabors.ImageSharp.MetaData.Profiles.Exif; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Transforms.Processors { /// /// Adjusts an image so that its orientation is suitable for viewing. Adjustments are based on EXIF metadata embedded in the image. @@ -18,83 +19,83 @@ namespace SixLabors.ImageSharp.Processing.Processors /// protected override void BeforeImageApply(Image source, Rectangle sourceRectangle) { - Orientation orientation = GetExifOrientation(source); + OrientationType orientation = GetExifOrientation(source); Size size = sourceRectangle.Size; switch (orientation) { - case Orientation.TopRight: + case OrientationType.TopRight: new FlipProcessor(FlipType.Horizontal).Apply(source, sourceRectangle); break; - case Orientation.BottomRight: + case OrientationType.BottomRight: new RotateProcessor((int)RotateType.Rotate180, size).Apply(source, sourceRectangle); break; - case Orientation.BottomLeft: + case OrientationType.BottomLeft: new FlipProcessor(FlipType.Vertical).Apply(source, sourceRectangle); break; - case Orientation.LeftTop: + case OrientationType.LeftTop: new RotateProcessor((int)RotateType.Rotate90, size).Apply(source, sourceRectangle); new FlipProcessor(FlipType.Horizontal).Apply(source, sourceRectangle); break; - case Orientation.RightTop: + case OrientationType.RightTop: new RotateProcessor((int)RotateType.Rotate90, size).Apply(source, sourceRectangle); break; - case Orientation.RightBottom: + case OrientationType.RightBottom: new FlipProcessor(FlipType.Vertical).Apply(source, sourceRectangle); new RotateProcessor((int)RotateType.Rotate270, size).Apply(source, sourceRectangle); break; - case Orientation.LeftBottom: + case OrientationType.LeftBottom: new RotateProcessor((int)RotateType.Rotate270, size).Apply(source, sourceRectangle); break; - case Orientation.Unknown: - case Orientation.TopLeft: + case OrientationType.Unknown: + case OrientationType.TopLeft: default: break; } } /// - protected override void OnApply(ImageFrame sourceBase, Rectangle sourceRectangle, Configuration config) + protected override void OnFrameApply(ImageFrame sourceBase, Rectangle sourceRectangle, Configuration config) { - // all processing happens at the image level within BeforeImageApply(); + // All processing happens at the image level within BeforeImageApply(); } /// /// Returns the current EXIF orientation /// /// The image to auto rotate. - /// The - private static Orientation GetExifOrientation(Image source) + /// The + private static OrientationType GetExifOrientation(Image source) { if (source.MetaData.ExifProfile == null) { - return Orientation.Unknown; + return OrientationType.Unknown; } ExifValue value = source.MetaData.ExifProfile.GetValue(ExifTag.Orientation); if (value == null) { - return Orientation.Unknown; + return OrientationType.Unknown; } - Orientation orientation; + OrientationType orientation; if (value.DataType == ExifDataType.Short) { - orientation = (Orientation)value.Value; + orientation = (OrientationType)value.Value; } else { - orientation = (Orientation)Convert.ToUInt16(value.Value); + orientation = (OrientationType)Convert.ToUInt16(value.Value); source.MetaData.ExifProfile.RemoveValue(ExifTag.Orientation); } - source.MetaData.ExifProfile.SetValue(ExifTag.Orientation, (ushort)Orientation.TopLeft); + source.MetaData.ExifProfile.SetValue(ExifTag.Orientation, (ushort)OrientationType.TopLeft); return orientation; } diff --git a/src/ImageSharp/Processing/Processors/Transforms/CenteredAffineTransformProcessor.cs b/src/ImageSharp/Processing/Transforms/Processors/CenteredAffineTransformProcessor.cs similarity index 86% rename from src/ImageSharp/Processing/Processors/Transforms/CenteredAffineTransformProcessor.cs rename to src/ImageSharp/Processing/Transforms/Processors/CenteredAffineTransformProcessor.cs index 6b8314d172..adeed55efd 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/CenteredAffineTransformProcessor.cs +++ b/src/ImageSharp/Processing/Transforms/Processors/CenteredAffineTransformProcessor.cs @@ -3,9 +3,10 @@ using System.Numerics; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Transforms.Resamplers; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Transforms.Processors { /// /// A base class that provides methods to allow the automatic centering of affine transforms @@ -27,9 +28,7 @@ namespace SixLabors.ImageSharp.Processing.Processors /// protected override Matrix3x2 GetProcessingMatrix(Rectangle sourceRectangle, Rectangle destinationRectangle) - { - return TransformHelpers.GetCenteredTransformMatrix(sourceRectangle, destinationRectangle, this.TransformMatrix); - } + => TransformHelpers.GetCenteredTransformMatrix(sourceRectangle, destinationRectangle, this.TransformMatrix); private static Size GetTransformedDimensions(Size sourceDimensions, Matrix3x2 matrix) { diff --git a/src/ImageSharp/Processing/Processors/Transforms/CenteredProjectiveTransformProcessor.cs b/src/ImageSharp/Processing/Transforms/Processors/CenteredProjectiveTransformProcessor.cs similarity index 93% rename from src/ImageSharp/Processing/Processors/Transforms/CenteredProjectiveTransformProcessor.cs rename to src/ImageSharp/Processing/Transforms/Processors/CenteredProjectiveTransformProcessor.cs index 081ea84610..5cdcde4839 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/CenteredProjectiveTransformProcessor.cs +++ b/src/ImageSharp/Processing/Transforms/Processors/CenteredProjectiveTransformProcessor.cs @@ -3,9 +3,10 @@ using System.Numerics; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Transforms.Resamplers; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Transforms.Processors { /// /// A base class that provides methods to allow the automatic centering of non-affine transforms diff --git a/src/ImageSharp/Processing/Transforms/Processors/CropProcessor.cs b/src/ImageSharp/Processing/Transforms/Processors/CropProcessor.cs new file mode 100644 index 0000000000..5462b34dca --- /dev/null +++ b/src/ImageSharp/Processing/Transforms/Processors/CropProcessor.cs @@ -0,0 +1,74 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using SixLabors.ImageSharp.Advanced; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.Primitives; + +namespace SixLabors.ImageSharp.Processing.Transforms.Processors +{ + /// + /// Provides methods to allow the cropping of an image. + /// + /// The pixel format. + internal class CropProcessor : TransformProcessorBase + where TPixel : struct, IPixel + { + /// + /// Initializes a new instance of the class. + /// + /// The target cropped rectangle. + public CropProcessor(Rectangle cropRectangle) + { + this.CropRectangle = cropRectangle; + } + + /// + /// Gets the width. + /// + public Rectangle CropRectangle { get; } + + /// + protected override Image CreateDestination(Image source, Rectangle sourceRectangle) + { + // We will always be creating the clone even for mutate because we may need to resize the canvas + IEnumerable> frames = source.Frames.Select(x => new ImageFrame(source.GetMemoryManager(), this.CropRectangle.Width, this.CropRectangle.Height, x.MetaData.Clone())); + + // Use the overload to prevent an extra frame being added + return new Image(source.GetConfiguration(), source.MetaData.Clone(), frames); + } + + /// + protected override void OnFrameApply(ImageFrame source, ImageFrame destination, Rectangle sourceRectangle, Configuration configuration) + { + // Handle resize dimensions identical to the original + if (source.Width == destination.Width && source.Height == destination.Height && sourceRectangle == this.CropRectangle) + { + // the cloned will be blank here copy all the pixel data over + source.GetPixelSpan().CopyTo(destination.GetPixelSpan()); + return; + } + + int minY = Math.Max(this.CropRectangle.Y, sourceRectangle.Y); + int maxY = Math.Min(this.CropRectangle.Bottom, sourceRectangle.Bottom); + int minX = Math.Max(this.CropRectangle.X, sourceRectangle.X); + int maxX = Math.Min(this.CropRectangle.Right, sourceRectangle.Right); + + Parallel.For( + minY, + maxY, + configuration.ParallelOptions, + y => + { + Span sourceRow = source.GetPixelRowSpan(y).Slice(minX); + Span targetRow = destination.GetPixelRowSpan(y - minY); + SpanHelper.Copy(sourceRow, targetRow, maxX - minX); + }); + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/Processors/EntropyCropProcessor.cs b/src/ImageSharp/Processing/Transforms/Processors/EntropyCropProcessor.cs new file mode 100644 index 0000000000..66b781517a --- /dev/null +++ b/src/ImageSharp/Processing/Transforms/Processors/EntropyCropProcessor.cs @@ -0,0 +1,75 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Advanced; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Binarization.Processors; +using SixLabors.ImageSharp.Processing.Convolution.Processors; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Primitives; + +namespace SixLabors.ImageSharp.Processing.Transforms.Processors +{ + /// + /// Provides methods to allow the cropping of an image to preserve areas of highest entropy. + /// + /// The pixel format. + internal class EntropyCropProcessor : ImageProcessor + where TPixel : struct, IPixel + { + /// + /// Initializes a new instance of the class. + /// + public EntropyCropProcessor() + : this(.5F) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The threshold to split the image. Must be between 0 and 1. + /// + /// is less than 0 or is greater than 1. + /// + public EntropyCropProcessor(float threshold) + { + Guard.MustBeBetweenOrEqualTo(threshold, 0, 1F, nameof(threshold)); + this.Threshold = threshold; + } + + /// + /// Gets the entropy threshold value. + /// + public float Threshold { get; } + + /// + protected override void BeforeImageApply(Image source, Rectangle sourceRectangle) + { + Rectangle rectangle; + + // All frames have be the same size so we only need to calculate the correct dimensions for the first frame + using (ImageFrame temp = source.Frames.RootFrame.Clone()) + { + Configuration configuration = source.GetConfiguration(); + + // Detect the edges. + new SobelProcessor(false).Apply(temp, sourceRectangle, configuration); + + // Apply threshold binarization filter. + new BinaryThresholdProcessor(this.Threshold).Apply(temp, sourceRectangle, configuration); + + // Search for the first white pixels + rectangle = ImageMaths.GetFilteredBoundingRectangle(temp, 0); + } + + new CropProcessor(rectangle).Apply(source, sourceRectangle); + } + + /// + protected override void OnFrameApply(ImageFrame sourceBase, Rectangle sourceRectangle, Configuration config) + { + // All processing happens at the image level within BeforeImageApply(); + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Processors/Transforms/FlipProcessor.cs b/src/ImageSharp/Processing/Transforms/Processors/FlipProcessor.cs similarity index 92% rename from src/ImageSharp/Processing/Processors/Transforms/FlipProcessor.cs rename to src/ImageSharp/Processing/Transforms/Processors/FlipProcessor.cs index 9b8b785b58..4c6cb166bf 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/FlipProcessor.cs +++ b/src/ImageSharp/Processing/Transforms/Processors/FlipProcessor.cs @@ -4,12 +4,12 @@ using System; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Helpers; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Transforms.Processors { /// /// Provides methods that allow the flipping of an image around its center point. @@ -33,7 +33,7 @@ namespace SixLabors.ImageSharp.Processing.Processors public FlipType FlipType { get; } /// - protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) + protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { switch (this.FlipType) { @@ -48,8 +48,7 @@ namespace SixLabors.ImageSharp.Processing.Processors } /// - /// Swaps the image at the X-axis, which goes horizontally through the middle - /// at half the height of the image. + /// Swaps the image at the X-axis, which goes horizontally through the middle at half the height of the image. /// /// The source image to apply the process to. /// The configuration. @@ -81,8 +80,7 @@ namespace SixLabors.ImageSharp.Processing.Processors } /// - /// Swaps the image at the Y-axis, which goes vertically through the middle - /// at half of the width of the image. + /// Swaps the image at the Y-axis, which goes vertically through the middle at half of the width of the image. /// /// The source image to apply the process to. /// The configuration. diff --git a/src/ImageSharp/Processing/Processors/Transforms/InterpolatedTransformProcessorBase.cs b/src/ImageSharp/Processing/Transforms/Processors/InterpolatedTransformProcessorBase.cs similarity index 95% rename from src/ImageSharp/Processing/Processors/Transforms/InterpolatedTransformProcessorBase.cs rename to src/ImageSharp/Processing/Transforms/Processors/InterpolatedTransformProcessorBase.cs index 27f9a1ace6..6e663f1e12 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/InterpolatedTransformProcessorBase.cs +++ b/src/ImageSharp/Processing/Transforms/Processors/InterpolatedTransformProcessorBase.cs @@ -4,8 +4,9 @@ using System; using System.Runtime.CompilerServices; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Transforms.Resamplers; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Transforms.Processors { /// /// The base class for performing interpolated affine and non-affine transforms. @@ -20,6 +21,7 @@ namespace SixLabors.ImageSharp.Processing.Processors /// The sampler to perform the transform operation. protected InterpolatedTransformProcessorBase(IResampler sampler) { + Guard.NotNull(sampler, nameof(sampler)); this.Sampler = sampler; } @@ -31,7 +33,7 @@ namespace SixLabors.ImageSharp.Processing.Processors /// /// Calculated the weights for the given point. /// This method uses more samples than the upscaled version to ensure edge pixels are correctly rendered. - /// Additionally the weights are nomalized. + /// Additionally the weights are normalized. /// /// The minimum sampling offset /// The maximum sampling offset diff --git a/src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor.cs b/src/ImageSharp/Processing/Transforms/Processors/ProjectiveTransformProcessor.cs similarity index 96% rename from src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor.cs rename to src/ImageSharp/Processing/Transforms/Processors/ProjectiveTransformProcessor.cs index e16cd9ee84..eb40c3f87f 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor.cs +++ b/src/ImageSharp/Processing/Transforms/Processors/ProjectiveTransformProcessor.cs @@ -7,16 +7,16 @@ using System.Linq; using System.Numerics; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Helpers; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Transforms.Resamplers; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Processors +// TODO: Doesn't work yet! Implement tests + Finish implementation + Document Matrix4x4 behavior +namespace SixLabors.ImageSharp.Processing.Transforms.Processors { /// /// Provides the base methods to perform non-affine transforms on an image. - /// TODO: Doesn't work yet! Implement tests + Finish implementation + Document Matrix4x4 behavior /// /// The pixel format. internal class ProjectiveTransformProcessor : InterpolatedTransformProcessorBase @@ -57,7 +57,7 @@ namespace SixLabors.ImageSharp.Processing.Processors } /// - protected override void OnApply(ImageFrame source, ImageFrame destination, Rectangle sourceRectangle, Configuration configuration) + protected override void OnFrameApply(ImageFrame source, ImageFrame destination, Rectangle sourceRectangle, Configuration configuration) { int height = this.TargetDimensions.Height; int width = this.TargetDimensions.Width; diff --git a/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs b/src/ImageSharp/Processing/Transforms/Processors/ResizeProcessor.cs similarity index 89% rename from src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs rename to src/ImageSharp/Processing/Transforms/Processors/ResizeProcessor.cs index 2e73920baa..7630db6a24 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs +++ b/src/ImageSharp/Processing/Transforms/Processors/ResizeProcessor.cs @@ -10,9 +10,11 @@ using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Transforms.Resamplers; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Transforms.Processors { /// /// Provides methods that allow the resizing of images using various algorithms. @@ -212,38 +214,39 @@ namespace SixLabors.ImageSharp.Processing.Processors protected override Image CreateDestination(Image source, Rectangle sourceRectangle) { // We will always be creating the clone even for mutate because we may need to resize the canvas - IEnumerable> frames = source.Frames.Select(x => new ImageFrame(source.GetMemoryManager(), this.Width, this.Height, x.MetaData.Clone())); // this will create places holders + IEnumerable> frames = source.Frames.Select(x => new ImageFrame(source.GetMemoryManager(), this.Width, this.Height, x.MetaData.Clone())); // Use the overload to prevent an extra frame being added return new Image(source.GetConfiguration(), source.MetaData.Clone(), frames); } /// - protected override void BeforeApply(ImageFrame source, ImageFrame destination, Rectangle sourceRectangle, Configuration configuration) + protected override void BeforeImageApply(Image source, Image destination, Rectangle sourceRectangle) { if (!(this.Sampler is NearestNeighborResampler)) { - // TODO: Optimization opportunity: if we could assume that all frames are of the same size, we can move this into 'BeforeImageApply()` + // Since all image frame dimensions have to be the same we can calculate this for all frames. + MemoryManager memoryManager = source.GetMemoryManager(); this.horizontalWeights = this.PrecomputeWeights( - source.MemoryManager, + memoryManager, this.ResizeRectangle.Width, sourceRectangle.Width); this.verticalWeights = this.PrecomputeWeights( - source.MemoryManager, + memoryManager, this.ResizeRectangle.Height, sourceRectangle.Height); } } /// - protected override void OnApply(ImageFrame source, ImageFrame cloned, Rectangle sourceRectangle, Configuration configuration) + protected override void OnFrameApply(ImageFrame source, ImageFrame destination, Rectangle sourceRectangle, Configuration configuration) { - // Jump out, we'll deal with that later. - if (source.Width == cloned.Width && source.Height == cloned.Height && sourceRectangle == this.ResizeRectangle) + // Handle resize dimensions identical to the original + if (source.Width == destination.Width && source.Height == destination.Height && sourceRectangle == this.ResizeRectangle) { // the cloned will be blank here copy all the pixel data over - source.GetPixelSpan().CopyTo(cloned.GetPixelSpan()); + source.GetPixelSpan().CopyTo(destination.GetPixelSpan()); return; } @@ -275,7 +278,7 @@ namespace SixLabors.ImageSharp.Processing.Processors { // Y coordinates of source points Span sourceRow = source.GetPixelRowSpan((int)(((y - startY) * heightFactor) + sourceY)); - Span targetRow = cloned.GetPixelRowSpan(y); + Span targetRow = destination.GetPixelRowSpan(y); for (int x = minX; x < maxX; x++) { @@ -336,18 +339,18 @@ namespace SixLabors.ImageSharp.Processing.Processors { // Ensure offsets are normalized for cropping and padding. WeightsWindow window = this.verticalWeights.Weights[y - startY]; - Span targetRow = cloned.GetPixelRowSpan(y); + Span targetRow = destination.GetPixelRowSpan(y); if (this.Compand) { for (int x = 0; x < width; x++) { // Destination color components - Vector4 destination = window.ComputeWeightedColumnSum(firstPassPixels, x, sourceY); - destination = destination.Compress(); + Vector4 destinationVector = window.ComputeWeightedColumnSum(firstPassPixels, x, sourceY); + destinationVector = destinationVector.Compress(); ref TPixel pixel = ref targetRow[x]; - pixel.PackFromVector4(destination); + pixel.PackFromVector4(destinationVector); } } else @@ -355,10 +358,10 @@ namespace SixLabors.ImageSharp.Processing.Processors for (int x = 0; x < width; x++) { // Destination color components - Vector4 destination = window.ComputeWeightedColumnSum(firstPassPixels, x, sourceY); + Vector4 destinationVector = window.ComputeWeightedColumnSum(firstPassPixels, x, sourceY); ref TPixel pixel = ref targetRow[x]; - pixel.PackFromVector4(destination); + pixel.PackFromVector4(destinationVector); } } }); @@ -366,9 +369,9 @@ namespace SixLabors.ImageSharp.Processing.Processors } /// - protected override void AfterApply(ImageFrame source, ImageFrame destination, Rectangle sourceRectangle, Configuration configuration) + protected override void AfterFrameApply(ImageFrame source, ImageFrame destination, Rectangle sourceRectangle, Configuration configuration) { - base.AfterApply(source, destination, sourceRectangle, configuration); + base.AfterFrameApply(source, destination, sourceRectangle, configuration); // TODO: An exception in the processing chain can leave these buffers undisposed. We should consider making image processors IDisposable! this.horizontalWeights?.Dispose(); diff --git a/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs b/src/ImageSharp/Processing/Transforms/Processors/RotateProcessor.cs similarity index 94% rename from src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs rename to src/ImageSharp/Processing/Transforms/Processors/RotateProcessor.cs index 824ae4310f..0cf42cbb72 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs +++ b/src/ImageSharp/Processing/Transforms/Processors/RotateProcessor.cs @@ -4,12 +4,12 @@ using System; using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Helpers; using SixLabors.ImageSharp.MetaData.Profiles.Exif; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Transforms.Resamplers; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Transforms.Processors { /// /// Provides methods that allow the rotating of images. @@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.Processing.Processors /// The angle of rotation in degrees. /// The source image size public RotateProcessor(float degrees, Size sourceSize) - : this(degrees, KnownResamplers.Bicubic, sourceSize) + : this(degrees, ResampleMode.Bicubic, sourceSize) { } @@ -46,14 +46,14 @@ namespace SixLabors.ImageSharp.Processing.Processors public float Degrees { get; } /// - protected override void OnApply(ImageFrame source, ImageFrame destination, Rectangle sourceRectangle, Configuration configuration) + protected override void OnFrameApply(ImageFrame source, ImageFrame destination, Rectangle sourceRectangle, Configuration configuration) { if (this.OptimizedApply(source, destination, configuration)) { return; } - base.OnApply(source, destination, sourceRectangle, configuration); + base.OnFrameApply(source, destination, sourceRectangle, configuration); } /// diff --git a/src/ImageSharp/Processing/Processors/Transforms/SkewProcessor.cs b/src/ImageSharp/Processing/Transforms/Processors/SkewProcessor.cs similarity index 91% rename from src/ImageSharp/Processing/Processors/Transforms/SkewProcessor.cs rename to src/ImageSharp/Processing/Transforms/Processors/SkewProcessor.cs index 8e3ab7c34f..cc3d901d6c 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/SkewProcessor.cs +++ b/src/ImageSharp/Processing/Transforms/Processors/SkewProcessor.cs @@ -2,9 +2,10 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Transforms.Resamplers; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Transforms.Processors { /// /// Provides methods that allow the skewing of images. @@ -20,7 +21,7 @@ namespace SixLabors.ImageSharp.Processing.Processors /// The angle in degrees to perform the skew along the y-axis. /// The source image size public SkewProcessor(float degreesX, float degreesY, Size sourceSize) - : this(degreesX, degreesY, KnownResamplers.Bicubic, sourceSize) + : this(degreesX, degreesY, ResampleMode.Bicubic, sourceSize) { } diff --git a/src/ImageSharp/Processing/Processors/Transforms/TransformProcessorBase.cs b/src/ImageSharp/Processing/Transforms/Processors/TransformProcessorBase.cs similarity index 87% rename from src/ImageSharp/Processing/Processors/Transforms/TransformProcessorBase.cs rename to src/ImageSharp/Processing/Transforms/Processors/TransformProcessorBase.cs index 7403a400e7..0ca5ee1911 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/TransformProcessorBase.cs +++ b/src/ImageSharp/Processing/Transforms/Processors/TransformProcessorBase.cs @@ -2,9 +2,10 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing.Processors +namespace SixLabors.ImageSharp.Processing.Transforms.Processors { /// /// The base class for all transform processors. Any processor that changes the dimensions of the image should inherit from this. diff --git a/src/ImageSharp/Processing/Processors/Transforms/WeightsBuffer.cs b/src/ImageSharp/Processing/Transforms/Processors/WeightsBuffer.cs similarity index 100% rename from src/ImageSharp/Processing/Processors/Transforms/WeightsBuffer.cs rename to src/ImageSharp/Processing/Transforms/Processors/WeightsBuffer.cs diff --git a/src/ImageSharp/Processing/Processors/Transforms/WeightsWindow.cs b/src/ImageSharp/Processing/Transforms/Processors/WeightsWindow.cs similarity index 100% rename from src/ImageSharp/Processing/Processors/Transforms/WeightsWindow.cs rename to src/ImageSharp/Processing/Transforms/Processors/WeightsWindow.cs diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/KnownResamplers.cs b/src/ImageSharp/Processing/Transforms/ResampleMode.cs similarity index 96% rename from src/ImageSharp/Processing/Transforms/Resamplers/KnownResamplers.cs rename to src/ImageSharp/Processing/Transforms/ResampleMode.cs index 2da98497b5..bbbdc3b265 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/KnownResamplers.cs +++ b/src/ImageSharp/Processing/Transforms/ResampleMode.cs @@ -1,12 +1,14 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing +using SixLabors.ImageSharp.Processing.Transforms.Resamplers; + +namespace SixLabors.ImageSharp.Processing.Transforms { /// /// Contains reusable static instances of known resampling algorithms /// - public static class KnownResamplers + public static class ResampleMode { /// /// Gets the Bicubic sampler that implements the bicubic kernel algorithm W(x) diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/BicubicResampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/BicubicResampler.cs index be9de9edaa..dd655a8a34 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/BicubicResampler.cs +++ b/src/ImageSharp/Processing/Transforms/Resamplers/BicubicResampler.cs @@ -1,12 +1,12 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing.Transforms.Resamplers { /// /// The function implements the bicubic kernel algorithm W(x) as described on /// Wikipedia - /// A commonly used algorithm within imageprocessing that preserves sharpness better than triangle interpolation. + /// A commonly used algorithm within image processing that preserves sharpness better than triangle interpolation. /// public class BicubicResampler : IResampler { @@ -38,4 +38,4 @@ namespace SixLabors.ImageSharp.Processing return result; } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/BoxResampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/BoxResampler.cs index 5aab0d07fa..d6f79721c4 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/BoxResampler.cs +++ b/src/ImageSharp/Processing/Transforms/Resamplers/BoxResampler.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing.Transforms.Resamplers { /// /// The function implements the box algorithm. Similar to nearest neighbor when upscaling. @@ -23,4 +23,4 @@ namespace SixLabors.ImageSharp.Processing return 0; } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/CatmullRomResampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/CatmullRomResampler.cs index 1c84676188..7284bf715d 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/CatmullRomResampler.cs +++ b/src/ImageSharp/Processing/Transforms/Resamplers/CatmullRomResampler.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing.Transforms.Resamplers { /// /// The Catmull-Rom filter is a well known standard Cubic Filter often used as a interpolation function. @@ -23,4 +23,4 @@ namespace SixLabors.ImageSharp.Processing return ImageMaths.GetBcValue(x, B, C); } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/HermiteResampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/HermiteResampler.cs index 33435059f1..2017a1cb54 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/HermiteResampler.cs +++ b/src/ImageSharp/Processing/Transforms/Resamplers/HermiteResampler.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing.Transforms.Resamplers { /// /// The Hermite filter is type of smoothed triangular interpolation Filter, @@ -22,4 +22,4 @@ namespace SixLabors.ImageSharp.Processing return ImageMaths.GetBcValue(x, B, C); } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/IResampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/IResampler.cs index 9a128a05be..6bc4feaf08 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/IResampler.cs +++ b/src/ImageSharp/Processing/Transforms/Resamplers/IResampler.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing.Transforms.Resamplers { /// /// Encapsulates an interpolation algorithm for resampling images. @@ -22,4 +22,4 @@ namespace SixLabors.ImageSharp.Processing /// float GetValue(float x); } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos2Resampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos2Resampler.cs index 29568db021..35735189a0 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos2Resampler.cs +++ b/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos2Resampler.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing.Transforms.Resamplers { /// /// The function implements the Lanczos kernel algorithm as described on @@ -29,4 +29,4 @@ namespace SixLabors.ImageSharp.Processing return 0F; } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos3Resampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos3Resampler.cs index 492ef69e4c..fa85767a64 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos3Resampler.cs +++ b/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos3Resampler.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing.Transforms.Resamplers { /// /// The function implements the Lanczos kernel algorithm as described on @@ -29,4 +29,4 @@ namespace SixLabors.ImageSharp.Processing return 0F; } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos5Resampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos5Resampler.cs index cae152a53c..ec6b7181a0 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos5Resampler.cs +++ b/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos5Resampler.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing.Transforms.Resamplers { /// /// The function implements the Lanczos kernel algorithm as described on @@ -29,4 +29,4 @@ namespace SixLabors.ImageSharp.Processing return 0F; } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos8Resampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos8Resampler.cs index b390c55419..c1f6aecf1c 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos8Resampler.cs +++ b/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos8Resampler.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing.Transforms.Resamplers { /// /// The function implements the Lanczos kernel algorithm as described on @@ -29,4 +29,4 @@ namespace SixLabors.ImageSharp.Processing return 0F; } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/MitchellNetravaliResampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/MitchellNetravaliResampler.cs index df351d9505..b7817400bb 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/MitchellNetravaliResampler.cs +++ b/src/ImageSharp/Processing/Transforms/Resamplers/MitchellNetravaliResampler.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing.Transforms.Resamplers { /// /// The function implements the mitchell algorithm as described on @@ -21,4 +21,4 @@ namespace SixLabors.ImageSharp.Processing return ImageMaths.GetBcValue(x, B, C); } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/NearestNeighborResampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/NearestNeighborResampler.cs index 7a7785be36..61155132eb 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/NearestNeighborResampler.cs +++ b/src/ImageSharp/Processing/Transforms/Resamplers/NearestNeighborResampler.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing.Transforms.Resamplers { /// /// The function implements the nearest neighbor algorithm. This uses an unscaled filter @@ -18,4 +18,4 @@ namespace SixLabors.ImageSharp.Processing return x; } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/RobidouxResampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/RobidouxResampler.cs index bd28d8da46..03a6e8677e 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/RobidouxResampler.cs +++ b/src/ImageSharp/Processing/Transforms/Resamplers/RobidouxResampler.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing.Transforms.Resamplers { /// /// The function implements the Robidoux algorithm. @@ -21,4 +21,4 @@ namespace SixLabors.ImageSharp.Processing return ImageMaths.GetBcValue(x, B, C); } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/RobidouxSharpResampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/RobidouxSharpResampler.cs index a345da3f42..83213c3f4e 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/RobidouxSharpResampler.cs +++ b/src/ImageSharp/Processing/Transforms/Resamplers/RobidouxSharpResampler.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing.Transforms.Resamplers { /// /// The function implements the Robidoux Sharp algorithm. @@ -21,4 +21,4 @@ namespace SixLabors.ImageSharp.Processing return ImageMaths.GetBcValue(x, B, C); } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/SplineResampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/SplineResampler.cs index ac5e2dedba..45f18a4a01 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/SplineResampler.cs +++ b/src/ImageSharp/Processing/Transforms/Resamplers/SplineResampler.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing.Transforms.Resamplers { /// /// The function implements the spline algorithm. @@ -21,4 +21,4 @@ namespace SixLabors.ImageSharp.Processing return ImageMaths.GetBcValue(x, B, C); } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/TriangleResampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/TriangleResampler.cs index 842da87e06..0fde54486e 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/TriangleResampler.cs +++ b/src/ImageSharp/Processing/Transforms/Resamplers/TriangleResampler.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing.Transforms.Resamplers { /// /// The function implements the triangle (bilinear) algorithm. @@ -29,4 +29,4 @@ namespace SixLabors.ImageSharp.Processing return 0F; } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/WelchResampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/WelchResampler.cs index 9e18a24710..01a07fed57 100644 --- a/src/ImageSharp/Processing/Transforms/Resamplers/WelchResampler.cs +++ b/src/ImageSharp/Processing/Transforms/Resamplers/WelchResampler.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing.Transforms.Resamplers { /// /// The function implements the welch algorithm. diff --git a/src/ImageSharp/Processing/Transforms/Resize.cs b/src/ImageSharp/Processing/Transforms/ResizeExtensions.cs similarity index 88% rename from src/ImageSharp/Processing/Transforms/Resize.cs rename to src/ImageSharp/Processing/Transforms/ResizeExtensions.cs index 285f3206dc..4101d3cff4 100644 --- a/src/ImageSharp/Processing/Transforms/Resize.cs +++ b/src/ImageSharp/Processing/Transforms/ResizeExtensions.cs @@ -2,16 +2,16 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Transforms.Processors; +using SixLabors.ImageSharp.Processing.Transforms.Resamplers; using SixLabors.Primitives; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Transforms { /// - /// Extension methods for the type. + /// Adds extensions that allow the application of resize operations to the type. /// - public static partial class ImageExtensions + public static class ResizeExtensions { /// /// Resizes an image in accordance with the given . @@ -23,7 +23,7 @@ namespace SixLabors.ImageSharp /// Passing zero for one of height or width within the resize options will automatically preserve the aspect ratio of the original image public static IImageProcessingContext Resize(this IImageProcessingContext source, ResizeOptions options) where TPixel : struct, IPixel - => source.ApplyProcessor(new ResizeProcessor(options, source.GetCurrentSize())); + => source.ApplyProcessor(new ResizeProcessor(options, source.GetCurrentSize())); /// /// Resizes an image to the given . @@ -35,7 +35,7 @@ namespace SixLabors.ImageSharp /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image public static IImageProcessingContext Resize(this IImageProcessingContext source, Size size) where TPixel : struct, IPixel - => Resize(source, size.Width, size.Height, KnownResamplers.Bicubic, false); + => Resize(source, size.Width, size.Height, ResampleMode.Bicubic, false); /// /// Resizes an image to the given . @@ -48,7 +48,7 @@ namespace SixLabors.ImageSharp /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image public static IImageProcessingContext Resize(this IImageProcessingContext source, Size size, bool compand) where TPixel : struct, IPixel - => Resize(source, size.Width, size.Height, KnownResamplers.Bicubic, compand); + => Resize(source, size.Width, size.Height, ResampleMode.Bicubic, compand); /// /// Resizes an image to the given width and height. @@ -61,7 +61,7 @@ namespace SixLabors.ImageSharp /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image public static IImageProcessingContext Resize(this IImageProcessingContext source, int width, int height) where TPixel : struct, IPixel - => Resize(source, width, height, KnownResamplers.Bicubic, false); + => Resize(source, width, height, ResampleMode.Bicubic, false); /// /// Resizes an image to the given width and height. @@ -75,7 +75,7 @@ namespace SixLabors.ImageSharp /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image public static IImageProcessingContext Resize(this IImageProcessingContext source, int width, int height, bool compand) where TPixel : struct, IPixel - => Resize(source, width, height, KnownResamplers.Bicubic, compand); + => Resize(source, width, height, ResampleMode.Bicubic, compand); /// /// Resizes an image to the given width and height with the given sampler. @@ -89,7 +89,7 @@ namespace SixLabors.ImageSharp /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image public static IImageProcessingContext Resize(this IImageProcessingContext source, int width, int height, IResampler sampler) where TPixel : struct, IPixel - => Resize(source, width, height, sampler, false); + => Resize(source, width, height, sampler, false); /// /// Resizes an image to the given width and height with the given sampler. @@ -103,7 +103,7 @@ namespace SixLabors.ImageSharp /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image public static IImageProcessingContext Resize(this IImageProcessingContext source, Size size, IResampler sampler, bool compand) where TPixel : struct, IPixel - => Resize(source, size.Width, size.Height, sampler, new Rectangle(0, 0, size.Width, size.Height), compand); + => Resize(source, size.Width, size.Height, sampler, new Rectangle(0, 0, size.Width, size.Height), compand); /// /// Resizes an image to the given width and height with the given sampler. @@ -118,7 +118,7 @@ namespace SixLabors.ImageSharp /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image public static IImageProcessingContext Resize(this IImageProcessingContext source, int width, int height, IResampler sampler, bool compand) where TPixel : struct, IPixel - => Resize(source, width, height, sampler, new Rectangle(0, 0, width, height), compand); + => Resize(source, width, height, sampler, new Rectangle(0, 0, width, height), compand); /// /// Resizes an image to the given width and height with the given sampler and @@ -147,7 +147,7 @@ namespace SixLabors.ImageSharp Rectangle targetRectangle, bool compand) where TPixel : struct, IPixel - => source.ApplyProcessor(new ResizeProcessor(sampler, width, height, source.GetCurrentSize(), targetRectangle, compand), sourceRectangle); + => source.ApplyProcessor(new ResizeProcessor(sampler, width, height, source.GetCurrentSize(), targetRectangle, compand), sourceRectangle); /// /// Resizes an image to the given width and height with the given sampler and source rectangle. @@ -171,6 +171,6 @@ namespace SixLabors.ImageSharp Rectangle targetRectangle, bool compand) where TPixel : struct, IPixel - => source.ApplyProcessor(new ResizeProcessor(sampler, width, height, source.GetCurrentSize(), targetRectangle, compand)); + => source.ApplyProcessor(new ResizeProcessor(sampler, width, height, source.GetCurrentSize(), targetRectangle, compand)); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/Options/ResizeHelper.cs b/src/ImageSharp/Processing/Transforms/ResizeHelper.cs similarity index 99% rename from src/ImageSharp/Processing/Transforms/Options/ResizeHelper.cs rename to src/ImageSharp/Processing/Transforms/ResizeHelper.cs index ba6f4509d8..0d500b1bce 100644 --- a/src/ImageSharp/Processing/Transforms/Options/ResizeHelper.cs +++ b/src/ImageSharp/Processing/Transforms/ResizeHelper.cs @@ -5,7 +5,7 @@ using System; using System.Linq; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing.Transforms { /// /// Provides methods to help calculate the target rectangle when resizing using the diff --git a/src/ImageSharp/Processing/Transforms/Options/ResizeMode.cs b/src/ImageSharp/Processing/Transforms/ResizeMode.cs similarity index 91% rename from src/ImageSharp/Processing/Transforms/Options/ResizeMode.cs rename to src/ImageSharp/Processing/Transforms/ResizeMode.cs index c88808f758..d81691cd37 100644 --- a/src/ImageSharp/Processing/Transforms/Options/ResizeMode.cs +++ b/src/ImageSharp/Processing/Transforms/ResizeMode.cs @@ -1,10 +1,10 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing.Transforms { /// - /// Enumerated resize modes to apply to resized images. + /// Enumerated resize modes to apply to images. /// public enum ResizeMode { @@ -22,7 +22,7 @@ namespace SixLabors.ImageSharp.Processing /// /// Pads the image to fit the bound of the container without resizing the /// original source. - /// When downscaling, performs the same functionality as + /// When downscaling, performs the same functionality as /// BoxPad, diff --git a/src/ImageSharp/Processing/Transforms/Options/ResizeOptions.cs b/src/ImageSharp/Processing/Transforms/ResizeOptions.cs similarity index 87% rename from src/ImageSharp/Processing/Transforms/Options/ResizeOptions.cs rename to src/ImageSharp/Processing/Transforms/ResizeOptions.cs index f13fa77c99..8d63847485 100644 --- a/src/ImageSharp/Processing/Transforms/Options/ResizeOptions.cs +++ b/src/ImageSharp/Processing/Transforms/ResizeOptions.cs @@ -3,9 +3,10 @@ using System.Collections.Generic; using System.Linq; +using SixLabors.ImageSharp.Processing.Transforms.Resamplers; using SixLabors.Primitives; -namespace SixLabors.ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing.Transforms { /// /// The resize options for resizing images against certain modes. @@ -35,7 +36,7 @@ namespace SixLabors.ImageSharp.Processing /// /// Gets or sets the sampler to perform the resize operation. /// - public IResampler Sampler { get; set; } = KnownResamplers.Bicubic; + public IResampler Sampler { get; set; } = ResampleMode.Bicubic; /// /// Gets or sets a value indicating whether to compress @@ -43,4 +44,4 @@ namespace SixLabors.ImageSharp.Processing /// public bool Compand { get; set; } = false; } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/Rotate.cs b/src/ImageSharp/Processing/Transforms/RotateExtensions.cs similarity index 78% rename from src/ImageSharp/Processing/Transforms/Rotate.cs rename to src/ImageSharp/Processing/Transforms/RotateExtensions.cs index faecdf91f9..e4a233ba45 100644 --- a/src/ImageSharp/Processing/Transforms/Rotate.cs +++ b/src/ImageSharp/Processing/Transforms/RotateExtensions.cs @@ -2,15 +2,15 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Transforms.Processors; +using SixLabors.ImageSharp.Processing.Transforms.Resamplers; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Transforms { /// - /// Extension methods for the type. + /// Adds extensions that allow the application of rotate operations to the type. /// - public static partial class ImageExtensions + public static class RotateExtensions { /// /// Rotates and flips an image by the given instructions. @@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp /// The public static IImageProcessingContext Rotate(this IImageProcessingContext source, RotateType rotateType) where TPixel : struct, IPixel - => Rotate(source, (float)rotateType); + => Rotate(source, (float)rotateType); /// /// Rotates an image by the given angle in degrees. @@ -32,7 +32,7 @@ namespace SixLabors.ImageSharp /// The public static IImageProcessingContext Rotate(this IImageProcessingContext source, float degrees) where TPixel : struct, IPixel - => Rotate(source, degrees, KnownResamplers.Bicubic); + => Rotate(source, degrees, ResampleMode.Bicubic); /// /// Rotates an image by the given angle in degrees using the specified sampling algorithm. @@ -44,6 +44,6 @@ namespace SixLabors.ImageSharp /// The public static IImageProcessingContext Rotate(this IImageProcessingContext source, float degrees, IResampler sampler) where TPixel : struct, IPixel - => source.ApplyProcessor(new RotateProcessor(degrees, sampler, source.GetCurrentSize())); + => source.ApplyProcessor(new RotateProcessor(degrees, sampler, source.GetCurrentSize())); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/RotateFlip.cs b/src/ImageSharp/Processing/Transforms/RotateFlipExtensions.cs similarity index 76% rename from src/ImageSharp/Processing/Transforms/RotateFlip.cs rename to src/ImageSharp/Processing/Transforms/RotateFlipExtensions.cs index 2ddcb151b2..693c0d8ad7 100644 --- a/src/ImageSharp/Processing/Transforms/RotateFlip.cs +++ b/src/ImageSharp/Processing/Transforms/RotateFlipExtensions.cs @@ -1,16 +1,14 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Transforms { /// - /// Extension methods for the type. + /// Adds extensions that allow the application of rotate-flip operations to the type. /// - public static partial class ImageExtensions + public static class RotateFlipExtensions { /// /// Rotates and flips an image by the given instructions. @@ -22,8 +20,6 @@ namespace SixLabors.ImageSharp /// The public static IImageProcessingContext RotateFlip(this IImageProcessingContext source, RotateType rotateType, FlipType flipType) where TPixel : struct, IPixel - { - return source.Rotate(rotateType).Flip(flipType); - } + => source.Rotate(rotateType).Flip(flipType); } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/Options/RotateType.cs b/src/ImageSharp/Processing/Transforms/RotateType.cs similarity index 92% rename from src/ImageSharp/Processing/Transforms/Options/RotateType.cs rename to src/ImageSharp/Processing/Transforms/RotateType.cs index 9f6d45f2bf..498ad4149a 100644 --- a/src/ImageSharp/Processing/Transforms/Options/RotateType.cs +++ b/src/ImageSharp/Processing/Transforms/RotateType.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -namespace SixLabors.ImageSharp.Processing +namespace SixLabors.ImageSharp.Processing.Transforms { /// /// Provides enumeration over how the image should be rotated. @@ -28,4 +28,4 @@ namespace SixLabors.ImageSharp.Processing /// Rotate270 = 270 } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/Skew.cs b/src/ImageSharp/Processing/Transforms/SkewExtensions.cs similarity index 77% rename from src/ImageSharp/Processing/Transforms/Skew.cs rename to src/ImageSharp/Processing/Transforms/SkewExtensions.cs index fb054211a0..686f2c87c8 100644 --- a/src/ImageSharp/Processing/Transforms/Skew.cs +++ b/src/ImageSharp/Processing/Transforms/SkewExtensions.cs @@ -2,15 +2,15 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Transforms.Processors; +using SixLabors.ImageSharp.Processing.Transforms.Resamplers; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Transforms { /// - /// Extension methods for the type. + /// Adds extensions that allow the application of skew operations to the type. /// - public static partial class ImageExtensions + public static class SkewExtensions { /// /// Skews an image by the given angles in degrees. @@ -22,7 +22,7 @@ namespace SixLabors.ImageSharp /// The public static IImageProcessingContext Skew(this IImageProcessingContext source, float degreesX, float degreesY) where TPixel : struct, IPixel - => Skew(source, degreesX, degreesY, KnownResamplers.Bicubic); + => Skew(source, degreesX, degreesY, ResampleMode.Bicubic); /// /// Skews an image by the given angles in degrees using the specified sampling algorithm. @@ -35,6 +35,6 @@ namespace SixLabors.ImageSharp /// The public static IImageProcessingContext Skew(this IImageProcessingContext source, float degreesX, float degreesY, IResampler sampler) where TPixel : struct, IPixel - => source.ApplyProcessor(new SkewProcessor(degreesX, degreesY, sampler, source.GetCurrentSize())); + => source.ApplyProcessor(new SkewProcessor(degreesX, degreesY, sampler, source.GetCurrentSize())); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/Transform.cs b/src/ImageSharp/Processing/Transforms/TransformExtensions.cs similarity index 91% rename from src/ImageSharp/Processing/Transforms/Transform.cs rename to src/ImageSharp/Processing/Transforms/TransformExtensions.cs index 66d5d5de7e..865511b26d 100644 --- a/src/ImageSharp/Processing/Transforms/Transform.cs +++ b/src/ImageSharp/Processing/Transforms/TransformExtensions.cs @@ -3,16 +3,16 @@ using System.Numerics; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Transforms.Processors; +using SixLabors.ImageSharp.Processing.Transforms.Resamplers; using SixLabors.Primitives; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Transforms { /// - /// Extension methods for the type. + /// Adds extensions that allow the application of composable transform operations to the type. /// - public static partial class ImageExtensions + public static class TransformExtensions { /// /// Transforms an image by the given matrix. @@ -23,7 +23,7 @@ namespace SixLabors.ImageSharp /// The public static IImageProcessingContext Transform(this IImageProcessingContext source, Matrix3x2 matrix) where TPixel : struct, IPixel - => Transform(source, matrix, KnownResamplers.Bicubic); + => Transform(source, matrix, ResampleMode.Bicubic); /// /// Transforms an image by the given matrix using the specified sampling algorithm. @@ -77,9 +77,7 @@ namespace SixLabors.ImageSharp IResampler sampler, Size destinationSize) where TPixel : struct, IPixel - { - return source.ApplyProcessor(new AffineTransformProcessor(matrix, sampler, destinationSize)); - } + => source.ApplyProcessor(new AffineTransformProcessor(matrix, sampler, destinationSize)); /// /// Transforms an image by the given matrix. @@ -90,7 +88,7 @@ namespace SixLabors.ImageSharp /// The internal static IImageProcessingContext Transform(this IImageProcessingContext source, Matrix4x4 matrix) where TPixel : struct, IPixel - => Transform(source, matrix, KnownResamplers.Bicubic); + => Transform(source, matrix, ResampleMode.Bicubic); /// /// Applies a projective transform to the image by the given matrix using the specified sampling algorithm. diff --git a/src/ImageSharp/Processing/Transforms/TransformHelpers.cs b/src/ImageSharp/Processing/Transforms/TransformHelpers.cs index 1567c11619..46dd134cec 100644 --- a/src/ImageSharp/Processing/Transforms/TransformHelpers.cs +++ b/src/ImageSharp/Processing/Transforms/TransformHelpers.cs @@ -7,7 +7,7 @@ using SixLabors.ImageSharp.MetaData.Profiles.Exif; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; -namespace SixLabors.ImageSharp +namespace SixLabors.ImageSharp.Processing.Transforms { /// /// Contains helper methods for working with affine and non-affine transforms diff --git a/src/ImageSharp/Image/ReadOrigin.cs b/src/ImageSharp/ReadOrigin.cs similarity index 100% rename from src/ImageSharp/Image/ReadOrigin.cs rename to src/ImageSharp/ReadOrigin.cs diff --git a/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs b/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs index ce1a88599a..d2f54f140f 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs @@ -3,17 +3,18 @@ // Licensed under the Apache License, Version 2.0. // -namespace SixLabors.ImageSharp.Benchmarks -{ - using System.Drawing; - using System.Drawing.Drawing2D; - using System.IO; - using System.Numerics; - - using BenchmarkDotNet.Attributes; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.IO; +using System.Numerics; +using BenchmarkDotNet.Attributes; - using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Drawing; +namespace SixLabors.ImageSharp.Benchmarks +{ public class DrawBeziers : BenchmarkBase { [Benchmark(Baseline = true, Description = "System.Drawing Draw Beziers")] diff --git a/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs b/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs index 4f40c001d9..a027108a19 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs @@ -3,6 +3,8 @@ // Licensed under the Apache License, Version 2.0. // +using SixLabors.ImageSharp.Processing.Drawing; + namespace SixLabors.ImageSharp.Benchmarks { using System.Drawing; @@ -13,19 +15,20 @@ namespace SixLabors.ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; using SixLabors.ImageSharp.PixelFormats; + using SixLabors.ImageSharp.Processing; public class DrawLines : BenchmarkBase { [Benchmark(Baseline = true, Description = "System.Drawing Draw Lines")] public void DrawPathSystemDrawing() { - using (Bitmap destination = new Bitmap(800, 800)) + using (var destination = new Bitmap(800, 800)) { - using (Graphics graphics = Graphics.FromImage(destination)) + using (var graphics = Graphics.FromImage(destination)) { graphics.InterpolationMode = InterpolationMode.Default; graphics.SmoothingMode = SmoothingMode.AntiAlias; - Pen pen = new Pen(System.Drawing.Color.HotPink, 10); + var pen = new Pen(System.Drawing.Color.HotPink, 10); graphics.DrawLines(pen, new[] { new PointF(10, 10), new PointF(550, 50), @@ -33,7 +36,7 @@ namespace SixLabors.ImageSharp.Benchmarks }); } - using (MemoryStream ms = new MemoryStream()) + using (var ms = new MemoryStream()) { destination.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); } @@ -43,7 +46,7 @@ namespace SixLabors.ImageSharp.Benchmarks [Benchmark(Description = "ImageSharp Draw Lines")] public void DrawLinesCore() { - using (Image image = new Image(800, 800)) + using (var image = new Image(800, 800)) { image.Mutate(x => x.DrawLines( Rgba32.HotPink, @@ -54,7 +57,7 @@ namespace SixLabors.ImageSharp.Benchmarks new Vector2(200, 400) })); - using (MemoryStream ms = new MemoryStream()) + using (var ms = new MemoryStream()) { image.SaveAsBmp(ms); } diff --git a/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs b/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs index fd8e4ad285..ab690f645e 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs @@ -3,17 +3,20 @@ // Licensed under the Apache License, Version 2.0. // -namespace SixLabors.ImageSharp.Benchmarks -{ - using System.Drawing; - using System.Drawing.Drawing2D; +using System.Drawing; +using System.Drawing.Drawing2D; +using BenchmarkDotNet.Attributes; +using System.IO; +using System.Numerics; - using BenchmarkDotNet.Attributes; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Drawing; +using SixLabors.ImageSharp.Processing.Overlays; - using System.IO; - using System.Numerics; +namespace SixLabors.ImageSharp.Benchmarks +{ - using SixLabors.ImageSharp.PixelFormats; public class DrawPolygon : BenchmarkBase { diff --git a/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs b/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs index f948c4921f..c53a97515c 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs @@ -3,25 +3,27 @@ // Licensed under the Apache License, Version 2.0. // -namespace SixLabors.ImageSharp.Benchmarks -{ - using System.Drawing; - using System.Drawing.Drawing2D; - using System.IO; - using System.Numerics; - using SixLabors.Shapes; - - using BenchmarkDotNet.Attributes; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.IO; +using System.Numerics; +using SixLabors.Shapes; +using BenchmarkDotNet.Attributes; - using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Drawing; +using SixLabors.ImageSharp.Processing.Overlays; +namespace SixLabors.ImageSharp.Benchmarks +{ public class FillPolygon : BenchmarkBase { private readonly Polygon shape; public FillPolygon() { - this.shape = new SixLabors.Shapes.Polygon(new LinearLineSegment(new Vector2(10, 10), + this.shape = new Polygon(new LinearLineSegment(new Vector2(10, 10), new Vector2(550, 50), new Vector2(200, 400))); } diff --git a/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs b/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs index b3890c101e..7bd55e9057 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs @@ -3,18 +3,21 @@ // Licensed under the Apache License, Version 2.0. // -namespace SixLabors.ImageSharp.Benchmarks -{ - using System.Drawing; - using System.Drawing.Drawing2D; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.Numerics; +using BenchmarkDotNet.Attributes; - using BenchmarkDotNet.Attributes; - using CoreRectangle = SixLabors.Primitives.Rectangle; - using CoreSize = SixLabors.Primitives.Size; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Drawing; +using SixLabors.ImageSharp.Processing.Overlays; +using CoreRectangle = SixLabors.Primitives.Rectangle; +using CoreSize = SixLabors.Primitives.Size; - using System.Numerics; +namespace SixLabors.ImageSharp.Benchmarks +{ - using SixLabors.ImageSharp.PixelFormats; public class FillRectangle : BenchmarkBase { @@ -39,7 +42,7 @@ namespace SixLabors.ImageSharp.Benchmarks { using (Image image = new Image(800, 800)) { - image.Mutate(x => x.Fill(Rgba32.HotPink, new CoreRectangle(10, 10, 190, 140))); + image.Mutate(x => x.Fill(Rgba32.HotPink, new CoreRectangle(10, 10, 190, 140))); return new CoreSize(image.Width, image.Height); } @@ -53,10 +56,10 @@ namespace SixLabors.ImageSharp.Benchmarks image.Mutate(x => x.FillPolygon( Rgba32.HotPink, new SixLabors.Primitives.PointF[] { - new Vector2(10, 10), - new Vector2(200, 10), - new Vector2(200, 150), - new Vector2(10, 150) })); + new Vector2(10, 10), + new Vector2(200, 10), + new Vector2(200, 150), + new Vector2(10, 150) })); return new CoreSize(image.Width, image.Height); } diff --git a/tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs b/tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs index 46d02e4197..059398c6c2 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs @@ -3,17 +3,22 @@ // Licensed under the Apache License, Version 2.0. // +using System.Drawing; +using System.Drawing.Drawing2D; +using System.IO; + +using BenchmarkDotNet.Attributes; + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Drawing; + +using CoreBrushes = SixLabors.ImageSharp.Processing.Drawing.Brushes.Brushes; + + namespace SixLabors.ImageSharp.Benchmarks { - using System.Drawing; - using System.Drawing.Drawing2D; - using System.IO; - - using BenchmarkDotNet.Attributes; - using SixLabors.ImageSharp.Drawing.Brushes; - using CoreBrushes = ImageSharp.Drawing.Brushes.Brushes; - using SixLabors.ImageSharp.PixelFormats; public class FillWithPattern { @@ -26,7 +31,7 @@ namespace SixLabors.ImageSharp.Benchmarks { graphics.SmoothingMode = SmoothingMode.AntiAlias; HatchBrush brush = new HatchBrush(HatchStyle.BackwardDiagonal, System.Drawing.Color.HotPink); - graphics.FillRectangle(brush, new Rectangle(0,0, 800,800)); // can't find a way to flood fill with a brush + graphics.FillRectangle(brush, new Rectangle(0, 0, 800, 800)); // can't find a way to flood fill with a brush } using (MemoryStream ms = new MemoryStream()) { diff --git a/tests/ImageSharp.Benchmarks/General/Array2D.cs b/tests/ImageSharp.Benchmarks/General/Array2D.cs index 02df1a19e2..60d89847fd 100644 --- a/tests/ImageSharp.Benchmarks/General/Array2D.cs +++ b/tests/ImageSharp.Benchmarks/General/Array2D.cs @@ -9,7 +9,18 @@ namespace SixLabors.ImageSharp.Benchmarks.General using BenchmarkDotNet.Attributes; - using SixLabors.ImageSharp.Memory; + using SixLabors.ImageSharp.Primitives; + + /** + * Method | Count | Mean | Error | StdDev | Scaled | ScaledSD | +-------------------------------------------- |------ |---------:|---------:|---------:|-------:|---------:| + 'Emulated 2D array access using flat array' | 32 | 224.2 ns | 4.739 ns | 13.75 ns | 0.65 | 0.07 | + 'Array access using 2D array' | 32 | 346.6 ns | 9.225 ns | 26.91 ns | 1.00 | 0.00 | + 'Array access using a jagged array' | 32 | 229.3 ns | 6.028 ns | 17.58 ns | 0.67 | 0.07 | + 'Array access using DenseMatrix' | 32 | 223.2 ns | 5.248 ns | 15.22 ns | 0.65 | 0.07 | + + * + */ public class Array2D { @@ -19,9 +30,9 @@ namespace SixLabors.ImageSharp.Benchmarks.General private float[][] jaggedData; - private Fast2DArray fastData; - - [Params(4, 16, 128)] + private DenseMatrix matrix; + + [Params(4, 16, 32)] public int Count { get; set; } public int Min { get; private set; } @@ -39,9 +50,9 @@ namespace SixLabors.ImageSharp.Benchmarks.General this.jaggedData[i] = new float[this.Count]; } - this.fastData = new Fast2DArray(this.array2D); + this.matrix = new DenseMatrix(this.array2D); - this.Min = this.Count / 2 - 10; + this.Min = (this.Count / 2) - 10; this.Min = Math.Max(0, this.Min); this.Max = this.Min + Math.Min(10, this.Count); } @@ -56,7 +67,9 @@ namespace SixLabors.ImageSharp.Benchmarks.General { for (int j = this.Min; j < this.Max; j++) { - s += a[count * i + j]; + ref float v = ref a[count * i + j]; + v = i * j; + s += v; } } return s; @@ -71,7 +84,9 @@ namespace SixLabors.ImageSharp.Benchmarks.General { for (int j = this.Min; j < this.Max; j++) { - s += a[i, j]; + ref float v = ref a[i, j]; + v = i * j; + s += v; } } return s; @@ -86,25 +101,29 @@ namespace SixLabors.ImageSharp.Benchmarks.General { for (int j = this.Min; j < this.Max; j++) { - s += a[i][j]; + ref float v = ref a[i][j]; + v = i * j; + s += v; } } return s; } - [Benchmark(Description = "Array access using Fast2DArray")] - public float ArrayFastIndex() + [Benchmark(Description = "Array access using DenseMatrix")] + public float ArrayMatrixIndex() { float s = 0; - Fast2DArray a = this.fastData; + DenseMatrix a = this.matrix; for (int i = this.Min; i < this.Max; i++) { for (int j = this.Min; j < this.Max; j++) { - s += a[i, j]; + ref float v = ref a[i, j]; + v = i * j; + s += v; } } return s; } } -} +} \ No newline at end of file diff --git a/tests/ImageSharp.Benchmarks/General/PixelConversion_ConvertFromRgba32.cs b/tests/ImageSharp.Benchmarks/General/PixelConversion_ConvertFromRgba32.cs index a1db525a69..f5bd135e12 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelConversion_ConvertFromRgba32.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelConversion_ConvertFromRgba32.cs @@ -1,4 +1,7 @@ // ReSharper disable InconsistentNaming + +using SixLabors.ImageSharp.PixelFormats; + namespace SixLabors.ImageSharp.Benchmarks.General { using System.Runtime.CompilerServices; diff --git a/tests/ImageSharp.Benchmarks/General/PixelConversion_ConvertToRgba32.cs b/tests/ImageSharp.Benchmarks/General/PixelConversion_ConvertToRgba32.cs index 782c792393..5656904fe0 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelConversion_ConvertToRgba32.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelConversion_ConvertToRgba32.cs @@ -1,4 +1,7 @@ // ReSharper disable InconsistentNaming + +using SixLabors.ImageSharp.PixelFormats; + namespace SixLabors.ImageSharp.Benchmarks.General { using System.Runtime.CompilerServices; diff --git a/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs b/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs index 674aef84c1..7f16be8521 100644 --- a/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs +++ b/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs @@ -3,6 +3,8 @@ // Licensed under the Apache License, Version 2.0. // +using SixLabors.ImageSharp.PixelFormats; + namespace SixLabors.ImageSharp.Benchmarks.Image { using System; diff --git a/tests/ImageSharp.Benchmarks/Image/DecodeBmp.cs b/tests/ImageSharp.Benchmarks/Image/DecodeBmp.cs index 142675fa7a..ea13efb55e 100644 --- a/tests/ImageSharp.Benchmarks/Image/DecodeBmp.cs +++ b/tests/ImageSharp.Benchmarks/Image/DecodeBmp.cs @@ -3,6 +3,8 @@ // Licensed under the Apache License, Version 2.0. // +using SixLabors.ImageSharp.PixelFormats; + namespace SixLabors.ImageSharp.Benchmarks.Image { using System.Drawing; diff --git a/tests/ImageSharp.Benchmarks/Image/DecodeFilteredPng.cs b/tests/ImageSharp.Benchmarks/Image/DecodeFilteredPng.cs index e295aee732..b08adf4df6 100644 --- a/tests/ImageSharp.Benchmarks/Image/DecodeFilteredPng.cs +++ b/tests/ImageSharp.Benchmarks/Image/DecodeFilteredPng.cs @@ -3,6 +3,8 @@ // Licensed under the Apache License, Version 2.0. // +using SixLabors.ImageSharp.PixelFormats; + namespace SixLabors.ImageSharp.Benchmarks.Image { using System.IO; diff --git a/tests/ImageSharp.Benchmarks/Image/DecodeGif.cs b/tests/ImageSharp.Benchmarks/Image/DecodeGif.cs index a65c9f9298..cc3401b580 100644 --- a/tests/ImageSharp.Benchmarks/Image/DecodeGif.cs +++ b/tests/ImageSharp.Benchmarks/Image/DecodeGif.cs @@ -3,6 +3,8 @@ // Licensed under the Apache License, Version 2.0. // +using SixLabors.ImageSharp.PixelFormats; + namespace SixLabors.ImageSharp.Benchmarks.Image { using System.Drawing; diff --git a/tests/ImageSharp.Benchmarks/Image/DecodePng.cs b/tests/ImageSharp.Benchmarks/Image/DecodePng.cs index eb13cf9290..f07e80a756 100644 --- a/tests/ImageSharp.Benchmarks/Image/DecodePng.cs +++ b/tests/ImageSharp.Benchmarks/Image/DecodePng.cs @@ -3,6 +3,8 @@ // Licensed under the Apache License, Version 2.0. // +using SixLabors.ImageSharp.PixelFormats; + namespace SixLabors.ImageSharp.Benchmarks.Image { using System.Drawing; diff --git a/tests/ImageSharp.Benchmarks/Image/EncodeBmp.cs b/tests/ImageSharp.Benchmarks/Image/EncodeBmp.cs index 86994f2d35..68c84ab85f 100644 --- a/tests/ImageSharp.Benchmarks/Image/EncodeBmp.cs +++ b/tests/ImageSharp.Benchmarks/Image/EncodeBmp.cs @@ -3,6 +3,8 @@ // Licensed under the Apache License, Version 2.0. // +using SixLabors.ImageSharp.PixelFormats; + namespace SixLabors.ImageSharp.Benchmarks.Image { using System.Drawing; diff --git a/tests/ImageSharp.Benchmarks/Image/EncodeGif.cs b/tests/ImageSharp.Benchmarks/Image/EncodeGif.cs index 7a6ddd79d7..e42881945a 100644 --- a/tests/ImageSharp.Benchmarks/Image/EncodeGif.cs +++ b/tests/ImageSharp.Benchmarks/Image/EncodeGif.cs @@ -3,6 +3,8 @@ // Licensed under the Apache License, Version 2.0. // +using SixLabors.ImageSharp.PixelFormats; + namespace SixLabors.ImageSharp.Benchmarks.Image { using System.Drawing; diff --git a/tests/ImageSharp.Benchmarks/Image/EncodeIndexedPng.cs b/tests/ImageSharp.Benchmarks/Image/EncodeIndexedPng.cs index e5eb295449..a4cc06e25f 100644 --- a/tests/ImageSharp.Benchmarks/Image/EncodeIndexedPng.cs +++ b/tests/ImageSharp.Benchmarks/Image/EncodeIndexedPng.cs @@ -3,6 +3,8 @@ // Licensed under the Apache License, Version 2.0. // +using SixLabors.ImageSharp.PixelFormats; + namespace SixLabors.ImageSharp.Benchmarks.Image { using System.IO; @@ -10,9 +12,8 @@ namespace SixLabors.ImageSharp.Benchmarks.Image using BenchmarkDotNet.Attributes; using SixLabors.ImageSharp; - using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats.Png; - using SixLabors.ImageSharp.Quantizers; + using SixLabors.ImageSharp.Processing.Quantization; using CoreImage = ImageSharp.Image; diff --git a/tests/ImageSharp.Benchmarks/Image/EncodePng.cs b/tests/ImageSharp.Benchmarks/Image/EncodePng.cs index 53522a51f3..ffd810f289 100644 --- a/tests/ImageSharp.Benchmarks/Image/EncodePng.cs +++ b/tests/ImageSharp.Benchmarks/Image/EncodePng.cs @@ -3,6 +3,8 @@ // Licensed under the Apache License, Version 2.0. // +using SixLabors.ImageSharp.PixelFormats; + namespace SixLabors.ImageSharp.Benchmarks.Image { using System.Drawing; @@ -11,8 +13,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Image using BenchmarkDotNet.Attributes; using SixLabors.ImageSharp.Formats.Png; - using SixLabors.ImageSharp.Quantizers; - using SixLabors.ImageSharp.Quantizers.Base; + using SixLabors.ImageSharp.Processing.Quantization; using SixLabors.ImageSharp.Tests; using CoreImage = ImageSharp.Image; diff --git a/tests/ImageSharp.Benchmarks/Image/Jpeg/DecodeJpeg.cs b/tests/ImageSharp.Benchmarks/Image/Jpeg/DecodeJpeg.cs index 6cb5f8a219..f090e828d4 100644 --- a/tests/ImageSharp.Benchmarks/Image/Jpeg/DecodeJpeg.cs +++ b/tests/ImageSharp.Benchmarks/Image/Jpeg/DecodeJpeg.cs @@ -3,6 +3,8 @@ // Licensed under the Apache License, Version 2.0. // +using SixLabors.ImageSharp.PixelFormats; + namespace SixLabors.ImageSharp.Benchmarks.Image.Jpeg { using System.Drawing; diff --git a/tests/ImageSharp.Benchmarks/Image/Jpeg/DecodeJpegMultiple.cs b/tests/ImageSharp.Benchmarks/Image/Jpeg/DecodeJpegMultiple.cs index bc60c56696..cf0f0a54cf 100644 --- a/tests/ImageSharp.Benchmarks/Image/Jpeg/DecodeJpegMultiple.cs +++ b/tests/ImageSharp.Benchmarks/Image/Jpeg/DecodeJpegMultiple.cs @@ -3,6 +3,8 @@ // Licensed under the Apache License, Version 2.0. // +using SixLabors.ImageSharp.PixelFormats; + namespace SixLabors.ImageSharp.Benchmarks.Image.Jpeg { using System.Collections.Generic; diff --git a/tests/ImageSharp.Benchmarks/Image/Jpeg/EncodeJpeg.cs b/tests/ImageSharp.Benchmarks/Image/Jpeg/EncodeJpeg.cs index 15861bd617..8a43c39329 100644 --- a/tests/ImageSharp.Benchmarks/Image/Jpeg/EncodeJpeg.cs +++ b/tests/ImageSharp.Benchmarks/Image/Jpeg/EncodeJpeg.cs @@ -3,6 +3,8 @@ // Licensed under the Apache License, Version 2.0. // +using SixLabors.ImageSharp.PixelFormats; + namespace SixLabors.ImageSharp.Benchmarks.Image.Jpeg { using System.Drawing; diff --git a/tests/ImageSharp.Benchmarks/Image/MultiImageBenchmarkBase.cs b/tests/ImageSharp.Benchmarks/Image/MultiImageBenchmarkBase.cs index 2ed2d42c0d..9bf6d73b6d 100644 --- a/tests/ImageSharp.Benchmarks/Image/MultiImageBenchmarkBase.cs +++ b/tests/ImageSharp.Benchmarks/Image/MultiImageBenchmarkBase.cs @@ -3,6 +3,7 @@ // Licensed under the Apache License, Version 2.0. // +using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Benchmarks.Image { diff --git a/tests/ImageSharp.Benchmarks/Samplers/Crop.cs b/tests/ImageSharp.Benchmarks/Samplers/Crop.cs index 3681ff6f20..d5ac6a6f10 100644 --- a/tests/ImageSharp.Benchmarks/Samplers/Crop.cs +++ b/tests/ImageSharp.Benchmarks/Samplers/Crop.cs @@ -3,14 +3,16 @@ // Licensed under the Apache License, Version 2.0. // +using SixLabors.ImageSharp.PixelFormats; + namespace SixLabors.ImageSharp.Benchmarks { using System.Drawing; using System.Drawing.Drawing2D; using BenchmarkDotNet.Attributes; - - using SixLabors.ImageSharp.PixelFormats; + using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Transforms; using CoreSize = SixLabors.Primitives.Size; diff --git a/tests/ImageSharp.Benchmarks/Samplers/DetectEdges.cs b/tests/ImageSharp.Benchmarks/Samplers/DetectEdges.cs index f65957128c..569b5bc441 100644 --- a/tests/ImageSharp.Benchmarks/Samplers/DetectEdges.cs +++ b/tests/ImageSharp.Benchmarks/Samplers/DetectEdges.cs @@ -3,6 +3,8 @@ // Licensed under the Apache License, Version 2.0. // +using SixLabors.ImageSharp.PixelFormats; + namespace SixLabors.ImageSharp.Benchmarks { using System.IO; @@ -10,6 +12,7 @@ namespace SixLabors.ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Convolution; using CoreImage = ImageSharp.Image; @@ -38,17 +41,17 @@ namespace SixLabors.ImageSharp.Benchmarks [Benchmark(Description = "ImageSharp DetectEdges")] public void ImageProcessorCoreDetectEdges() { - this.image.Mutate(x => x.DetectEdges(EdgeDetection.Kayyali)); - this.image.Mutate(x => x.DetectEdges(EdgeDetection.Kayyali)); - this.image.Mutate(x => x.DetectEdges(EdgeDetection.Kirsch)); - this.image.Mutate(x => x.DetectEdges(EdgeDetection.Lapacian3X3)); - this.image.Mutate(x => x.DetectEdges(EdgeDetection.Lapacian5X5)); - this.image.Mutate(x => x.DetectEdges(EdgeDetection.LaplacianOfGaussian)); - this.image.Mutate(x => x.DetectEdges(EdgeDetection.Prewitt)); - this.image.Mutate(x => x.DetectEdges(EdgeDetection.RobertsCross)); - this.image.Mutate(x => x.DetectEdges(EdgeDetection.Robinson)); - this.image.Mutate(x => x.DetectEdges(EdgeDetection.Scharr)); - this.image.Mutate(x => x.DetectEdges(EdgeDetection.Sobel)); + this.image.Mutate(x => x.DetectEdges(EdgeDetectionOperators.Kayyali)); + this.image.Mutate(x => x.DetectEdges(EdgeDetectionOperators.Kayyali)); + this.image.Mutate(x => x.DetectEdges(EdgeDetectionOperators.Kirsch)); + this.image.Mutate(x => x.DetectEdges(EdgeDetectionOperators.Laplacian3x3)); + this.image.Mutate(x => x.DetectEdges(EdgeDetectionOperators.Laplacian5x5)); + this.image.Mutate(x => x.DetectEdges(EdgeDetectionOperators.LaplacianOfGaussian)); + this.image.Mutate(x => x.DetectEdges(EdgeDetectionOperators.Prewitt)); + this.image.Mutate(x => x.DetectEdges(EdgeDetectionOperators.RobertsCross)); + this.image.Mutate(x => x.DetectEdges(EdgeDetectionOperators.Robinson)); + this.image.Mutate(x => x.DetectEdges(EdgeDetectionOperators.Scharr)); + this.image.Mutate(x => x.DetectEdges(EdgeDetectionOperators.Sobel)); } } } diff --git a/tests/ImageSharp.Benchmarks/Samplers/Glow.cs b/tests/ImageSharp.Benchmarks/Samplers/Glow.cs index 5f4e2d75b4..51b1366490 100644 --- a/tests/ImageSharp.Benchmarks/Samplers/Glow.cs +++ b/tests/ImageSharp.Benchmarks/Samplers/Glow.cs @@ -8,17 +8,16 @@ namespace SixLabors.ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; using SixLabors.ImageSharp.PixelFormats; - using SixLabors.ImageSharp.Processing.Processors; + using CoreSize = SixLabors.Primitives.Size; - using SixLabors.ImageSharp.Processing; using System.Numerics; using System; using System.Threading.Tasks; using SixLabors.ImageSharp.Memory; using SixLabors.Primitives; - using SixLabors.ImageSharp.Helpers; - using SixLabors.ImageSharp.Advanced; + using SixLabors.ImageSharp.Processing.Overlays.Processors; + using SixLabors.ImageSharp.Processing.Processors; public class Glow : BenchmarkBase { @@ -28,7 +27,7 @@ namespace SixLabors.ImageSharp.Benchmarks [GlobalSetup] public void Setup() { - this.bulk = new GlowProcessor(Configuration.Default.MemoryManager, NamedColors.Beige, 800 * .5f, GraphicsOptions.Default); + this.bulk = new GlowProcessor(NamedColors.Beige, 800 * .5f, GraphicsOptions.Default); this.parallel = new GlowProcessorParallel(NamedColors.Beige) { Radius = 800 * .5f, }; } @@ -75,7 +74,7 @@ namespace SixLabors.ImageSharp.Benchmarks public float Radius { get; set; } /// - protected override void OnApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) + protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { int startY = sourceRectangle.Y; int endY = sourceRectangle.Bottom; diff --git a/tests/ImageSharp.Benchmarks/Samplers/Resize.cs b/tests/ImageSharp.Benchmarks/Samplers/Resize.cs index 6e7e2c8c48..0a47306860 100644 --- a/tests/ImageSharp.Benchmarks/Samplers/Resize.cs +++ b/tests/ImageSharp.Benchmarks/Samplers/Resize.cs @@ -11,6 +11,8 @@ namespace SixLabors.ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; using SixLabors.ImageSharp.PixelFormats; + using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Transforms; using CoreSize = SixLabors.Primitives.Size; diff --git a/tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs b/tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs index ec46e66107..121d93dac8 100644 --- a/tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs +++ b/tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs @@ -4,6 +4,8 @@ using System; using System.Collections.Generic; using System.Text; + +using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.Primitives; using Xunit; diff --git a/tests/ImageSharp.Tests/ComplexIntegrationTests.cs b/tests/ImageSharp.Tests/ComplexIntegrationTests.cs index ad4676872f..86703959aa 100644 --- a/tests/ImageSharp.Tests/ComplexIntegrationTests.cs +++ b/tests/ImageSharp.Tests/ComplexIntegrationTests.cs @@ -3,6 +3,7 @@ using SixLabors.ImageSharp.Formats.Jpeg; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Transforms; using SixLabors.Primitives; using Xunit; diff --git a/tests/ImageSharp.Tests/Drawing/BeziersTests.cs b/tests/ImageSharp.Tests/Drawing/BeziersTests.cs index 5ffd9f5f14..a0f62c4e79 100644 --- a/tests/ImageSharp.Tests/Drawing/BeziersTests.cs +++ b/tests/ImageSharp.Tests/Drawing/BeziersTests.cs @@ -1,13 +1,12 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; -using System.Diagnostics.CodeAnalysis; -using System.IO; using System.Numerics; -using SixLabors.ImageSharp.Drawing; + using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Tests.Drawing; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Drawing; +using SixLabors.ImageSharp.Processing.Overlays; using Xunit; namespace SixLabors.ImageSharp.Tests.Drawing @@ -68,9 +67,9 @@ namespace SixLabors.ImageSharp.Tests.Drawing new Vector2(240, 30), new Vector2(300, 400) })); - image.Save($"{path}/Opacity.png"); + image.Save($"{path}/Opacity.png"); - //shift background color towards forground color by the opacity amount + //shift background color towards foreground color by the opacity amount Rgba32 mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); using (PixelAccessor sourcePixels = image.Lock()) diff --git a/tests/ImageSharp.Tests/Drawing/BlendedShapes.cs b/tests/ImageSharp.Tests/Drawing/BlendedShapes.cs index df029d2d72..993adb1699 100644 --- a/tests/ImageSharp.Tests/Drawing/BlendedShapes.cs +++ b/tests/ImageSharp.Tests/Drawing/BlendedShapes.cs @@ -4,17 +4,19 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Drawing; using SixLabors.Primitives; using Xunit; namespace SixLabors.ImageSharp.Tests.Drawing { + using SixLabors.ImageSharp.Processing; + public class BlendedShapes { public static IEnumerable modes = ((PixelBlenderMode[])Enum.GetValues(typeof(PixelBlenderMode))) - .Select(x=> new object[] { x }); + .Select(x => new object[] { x }); [Theory] [WithBlankImages(nameof(modes), 250, 250, PixelTypes.Rgba32)] @@ -25,7 +27,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing { var scaleX = (img.Width / 100); var scaleY = (img.Height / 100); - img.Mutate(x=>x + img.Mutate(x => x .Fill(NamedColors.DarkBlue, new Rectangle(0 * scaleX, 40 * scaleY, 100 * scaleX, 20 * scaleY)) .Fill(NamedColors.HotPink, new Rectangle(20 * scaleX, 0 * scaleY, 30 * scaleX, 100 * scaleY), new ImageSharp.GraphicsOptions(true) { @@ -44,7 +46,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing { var scaleX = (img.Width / 100); var scaleY = (img.Height / 100); - img.Mutate(x=>x.Fill(NamedColors.DarkBlue, new Rectangle(0* scaleX, 40 * scaleY, 100 * scaleX, 20 * scaleY))); + img.Mutate(x => x.Fill(NamedColors.DarkBlue, new Rectangle(0 * scaleX, 40 * scaleY, 100 * scaleX, 20 * scaleY))); img.Mutate(x => x.Fill(NamedColors.HotPink, new Rectangle(20 * scaleX, 0 * scaleY, 30 * scaleX, 100 * scaleY), new ImageSharp.GraphicsOptions(true) { BlenderMode = mode @@ -66,7 +68,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing { var scaleX = (img.Width / 100); var scaleY = (img.Height / 100); - img.Mutate(x=>x.Fill(NamedColors.DarkBlue, new Rectangle(0 * scaleX, 40, 100 * scaleX, 20* scaleY))); + img.Mutate(x => x.Fill(NamedColors.DarkBlue, new Rectangle(0 * scaleX, 40, 100 * scaleX, 20 * scaleY))); img.Mutate(x => x.Fill(NamedColors.HotPink, new Rectangle(20 * scaleX, 0, 30 * scaleX, 100 * scaleY), new ImageSharp.GraphicsOptions(true) { BlenderMode = mode @@ -95,7 +97,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing { var scaleX = (img.Width / 100); var scaleY = (img.Height / 100); - img.Mutate(x => x.Fill(NamedColors.DarkBlue, new Rectangle(0 * scaleX, 40* scaleY, 100 * scaleX, 20 * scaleY))); + img.Mutate(x => x.Fill(NamedColors.DarkBlue, new Rectangle(0 * scaleX, 40 * scaleY, 100 * scaleX, 20 * scaleY))); img.Mutate(x => x.Fill(NamedColors.Black, new SixLabors.Shapes.EllipsePolygon(40 * scaleX, 50 * scaleY, 50 * scaleX, 50 * scaleY), new ImageSharp.GraphicsOptions(true) { BlenderMode = mode diff --git a/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs b/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs index 5fcb860be5..cf65833ea6 100644 --- a/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs +++ b/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs @@ -3,14 +3,16 @@ using System; using System.Numerics; -using SixLabors.ImageSharp.Helpers; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Drawing; using SixLabors.Primitives; using Xunit; namespace SixLabors.ImageSharp.Tests { + using SixLabors.ImageSharp.Processing.Transforms; + public class DrawImageTest : FileTestBase { private const PixelTypes PixelTypes = Tests.PixelTypes.Rgba32; @@ -64,7 +66,7 @@ namespace SixLabors.ImageSharp.Tests // We pass a new rectangle here based on the dest bounds since we've offset the matrix blend.Mutate(x => x.Transform( centeredMatrix, - KnownResamplers.Bicubic, + ResampleMode.Bicubic, new Rectangle(0, 0, destBounds.Width, destBounds.Height))); var position = new Point((image.Width - blend.Width) / 2, (image.Height - blend.Height) / 2); diff --git a/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs b/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs index 429acafb95..dbf0e6ce93 100644 --- a/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs +++ b/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs @@ -1,13 +1,14 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System.IO; using System.Numerics; -using SixLabors.ImageSharp.Drawing.Pens; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Drawing; +using SixLabors.ImageSharp.Processing.Drawing.Pens; +using SixLabors.ImageSharp.Processing.Overlays; using SixLabors.Shapes; using Xunit; -using ShapePath = SixLabors.Shapes.Path; namespace SixLabors.ImageSharp.Tests.Drawing { @@ -17,18 +18,18 @@ namespace SixLabors.ImageSharp.Tests.Drawing public void ImageShouldBeOverlayedByPath() { string path = TestEnvironment.CreateOutputDirectory("Drawing", "Path"); - using (Image image = new Image(500, 500)) + using (var image = new Image(500, 500)) { - LinearLineSegment linerSegemnt = new LinearLineSegment( + var linerSegemnt = new LinearLineSegment( new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300)); - CubicBezierLineSegment bazierSegment = new CubicBezierLineSegment(new Vector2(50, 300), + var bazierSegment = new CubicBezierLineSegment(new Vector2(50, 300), new Vector2(500, 500), new Vector2(60, 10), new Vector2(10, 400)); - ShapePath p = new ShapePath(linerSegemnt, bazierSegment); + var p = new Path(linerSegemnt, bazierSegment); image.Mutate(x => x .BackgroundColor(Rgba32.Blue) @@ -52,23 +53,23 @@ namespace SixLabors.ImageSharp.Tests.Drawing { string path = TestEnvironment.CreateOutputDirectory("Drawing", "Path"); - Rgba32 color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150); + var color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150); - LinearLineSegment linerSegemnt = new LinearLineSegment( + var linerSegemnt = new LinearLineSegment( new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) ); - CubicBezierLineSegment bazierSegment = new CubicBezierLineSegment(new Vector2(50, 300), + var bazierSegment = new CubicBezierLineSegment(new Vector2(50, 300), new Vector2(500, 500), new Vector2(60, 10), new Vector2(10, 400)); - ShapePath p = new ShapePath(linerSegemnt, bazierSegment); + var p = new Path(linerSegemnt, bazierSegment); - using (Image image = new Image(500, 500)) + using (var image = new Image(500, 500)) { image.Mutate(x => x .BackgroundColor(Rgba32.Blue) @@ -76,7 +77,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing image.Save($"{path}/Opacity.png"); //shift background color towards forground color by the opacity amount - Rgba32 mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); + var mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); using (PixelAccessor sourcePixels = image.Lock()) { @@ -98,7 +99,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing using (var image = new Image(256, 256)) { image.Mutate(x => x.Fill(Rgba32.Black)); - var pen = Pens.Solid(Rgba32.White, 5f); + Pen pen = Pens.Solid(Rgba32.White, 5f); for (int i = 0; i < 300; i += 20) { diff --git a/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs b/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs index d37058f5d1..7db88e9597 100644 --- a/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs @@ -2,21 +2,24 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.IO; -using SixLabors.ImageSharp.Drawing; -using SixLabors.ImageSharp.Drawing.Brushes; -using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Drawing; +using SixLabors.ImageSharp.Processing.Drawing.Brushes; + using Xunit; namespace SixLabors.ImageSharp.Tests.Drawing { + using SixLabors.ImageSharp.Primitives; + using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Transforms; + public class FillPatternBrushTests : FileTestBase { private void Test(string name, Rgba32 background, IBrush brush, Rgba32[,] expectedPattern) { string path = TestEnvironment.CreateOutputDirectory("Fill", "PatternBrush"); - using (Image image = new Image(20, 20)) + using (var image = new Image(20, 20)) { image.Mutate(x => x .Fill(background) @@ -27,15 +30,15 @@ namespace SixLabors.ImageSharp.Tests.Drawing using (PixelAccessor sourcePixels = image.Lock()) { // lets pick random spots to start checking - Random r = new Random(); - Fast2DArray expectedPatternFast = new Fast2DArray(expectedPattern); - int xStride = expectedPatternFast.Width; - int yStride = expectedPatternFast.Height; + var r = new Random(); + var expectedPatternFast = new DenseMatrix(expectedPattern); + int xStride = expectedPatternFast.Columns; + int yStride = expectedPatternFast.Rows; int offsetX = r.Next(image.Width / xStride) * xStride; int offsetY = r.Next(image.Height / yStride) * yStride; - for (int x = 0; x < xStride; x++) + for (var x = 0; x < xStride; x++) { - for (int y = 0; y < yStride; y++) + for (var y = 0; y < yStride; y++) { int actualX = x + offsetX; int actualY = y + offsetY; diff --git a/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs b/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs index 79ebf47787..c995dd31b4 100644 --- a/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs @@ -2,12 +2,16 @@ // Licensed under the Apache License, Version 2.0. using System.Numerics; -using SixLabors.ImageSharp.Drawing; -using SixLabors.ImageSharp.Drawing.Pens; -using SixLabors.ImageSharp.Drawing.Processors; + using Moq; using Xunit; -using SixLabors.ImageSharp.Drawing.Brushes; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Primitives; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Drawing; +using SixLabors.ImageSharp.Processing.Drawing.Brushes; +using SixLabors.ImageSharp.Processing.Drawing.Pens; +using SixLabors.ImageSharp.Processing.Drawing.Processors; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Tests.Drawing diff --git a/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs b/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs index 6eb139baca..aa360c8933 100644 --- a/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs @@ -1,29 +1,26 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; -using System.Diagnostics.CodeAnalysis; -using System.IO; using System.Numerics; -using SixLabors.ImageSharp.Drawing; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Tests.Drawing; +using SixLabors.ImageSharp.Processing.Drawing; using Xunit; namespace SixLabors.ImageSharp.Tests.Drawing { + using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Overlays; + public class FillSolidBrushTests : FileTestBase { [Fact] public void ImageShouldBeFloodFilledWithColorOnDefaultBackground() { string path = TestEnvironment.CreateOutputDirectory("Fill", "SolidBrush"); - using (Image image = new Image(500, 500)) + using (var image = new Image(500, 500)) { - image.Mutate(x => x - .Fill(Rgba32.HotPink)); - image - .Save($"{path}/DefaultBack.png"); + image.Mutate(x => x.Fill(Rgba32.HotPink)); + image.Save($"{path}/DefaultBack.png"); using (PixelAccessor sourcePixels = image.Lock()) { @@ -38,7 +35,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing public void ImageShouldBeFloodFilledWithColor() { string path = TestEnvironment.CreateOutputDirectory("Fill", "SolidBrush"); - using (Image image = new Image(500, 500)) + using (var image = new Image(500, 500)) { image.Mutate(x => x .BackgroundColor(Rgba32.Blue) @@ -58,9 +55,9 @@ namespace SixLabors.ImageSharp.Tests.Drawing public void ImageShouldBeFloodFilledWithColorOpacity() { string path = TestEnvironment.CreateOutputDirectory("Fill", "SolidBrush"); - using (Image image = new Image(500, 500)) + using (var image = new Image(500, 500)) { - Rgba32 color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150); + var color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150); image.Mutate(x => x .BackgroundColor(Rgba32.Blue) @@ -68,7 +65,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing image.Save($"{path}/Opacity.png"); //shift background color towards forground color by the opacity amount - Rgba32 mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); + var mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); using (PixelAccessor sourcePixels = image.Lock()) diff --git a/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs index 6c0670a85e..0e0df6844a 100644 --- a/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs @@ -1,17 +1,18 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System.IO; using System.Numerics; -using SixLabors.ImageSharp.Drawing; -using SixLabors.ImageSharp.Drawing.Pens; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Tests.Drawing; +using SixLabors.ImageSharp.Processing.Drawing; +using SixLabors.ImageSharp.Processing.Drawing.Pens; using SixLabors.Shapes; using Xunit; namespace SixLabors.ImageSharp.Tests.Drawing { + using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Overlays; + public class LineComplexPolygonTests : FileTestBase { [Fact] @@ -19,17 +20,17 @@ namespace SixLabors.ImageSharp.Tests.Drawing { string path = TestEnvironment.CreateOutputDirectory("Drawing", "LineComplexPolygon"); - Polygon simplePath = new Polygon(new LinearLineSegment( + var simplePath = new Polygon(new LinearLineSegment( new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300))); - Polygon hole1 = new Polygon(new LinearLineSegment( + var hole1 = new Polygon(new LinearLineSegment( new Vector2(37, 85), new Vector2(93, 85), new Vector2(65, 137))); - using (Image image = new Image(500, 500)) + using (var image = new Image(500, 500)) { image.Mutate(x => x .BackgroundColor(Rgba32.Blue) @@ -66,17 +67,17 @@ namespace SixLabors.ImageSharp.Tests.Drawing public void ImageShouldBeOverlayedByPolygonOutlineNoOverlapping() { string path = TestEnvironment.CreateOutputDirectory("Drawing", "LineComplexPolygon"); - Polygon simplePath = new Polygon(new LinearLineSegment( + var simplePath = new Polygon(new LinearLineSegment( new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300))); - Polygon hole1 = new Polygon(new LinearLineSegment( + var hole1 = new Polygon(new LinearLineSegment( new Vector2(207, 25), new Vector2(263, 25), new Vector2(235, 57))); - using (Image image = new Image(500, 500)) + using (var image = new Image(500, 500)) { image.Mutate(x => x .BackgroundColor(Rgba32.Blue) @@ -114,17 +115,17 @@ namespace SixLabors.ImageSharp.Tests.Drawing public void ImageShouldBeOverlayedByPolygonOutlineOverlapping() { string path = TestEnvironment.CreateOutputDirectory("Drawing", "LineComplexPolygon"); - Polygon simplePath = new Polygon(new LinearLineSegment( + var simplePath = new Polygon(new LinearLineSegment( new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300))); - Polygon hole1 = new Polygon(new LinearLineSegment( + var hole1 = new Polygon(new LinearLineSegment( new Vector2(37, 85), new Vector2(130, 40), new Vector2(65, 137))); - using (Image image = new Image(500, 500)) + using (var image = new Image(500, 500)) { image.Mutate(x => x .BackgroundColor(Rgba32.Blue) @@ -157,17 +158,17 @@ namespace SixLabors.ImageSharp.Tests.Drawing public void ImageShouldBeOverlayedByPolygonOutlineDashed() { string path = TestEnvironment.CreateOutputDirectory("Drawing", "LineComplexPolygon"); - Polygon simplePath = new Polygon(new LinearLineSegment( + var simplePath = new Polygon(new LinearLineSegment( new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300))); - Polygon hole1 = new Polygon(new LinearLineSegment( + var hole1 = new Polygon(new LinearLineSegment( new Vector2(37, 85), new Vector2(93, 85), new Vector2(65, 137))); - using (Image image = new Image(500, 500)) + using (var image = new Image(500, 500)) { image.Mutate(x => x .BackgroundColor(Rgba32.Blue) @@ -181,18 +182,18 @@ namespace SixLabors.ImageSharp.Tests.Drawing public void ImageShouldBeOverlayedPolygonOutlineWithOpacity() { string path = TestEnvironment.CreateOutputDirectory("Drawing", "LineComplexPolygon"); - Polygon simplePath = new Polygon(new LinearLineSegment( + var simplePath = new Polygon(new LinearLineSegment( new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300))); - Polygon hole1 = new Polygon(new LinearLineSegment( + var hole1 = new Polygon(new LinearLineSegment( new Vector2(37, 85), new Vector2(93, 85), new Vector2(65, 137))); - Rgba32 color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150); + var color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150); - using (Image image = new Image(500, 500)) + using (var image = new Image(500, 500)) { image.Mutate(x => x .BackgroundColor(Rgba32.Blue) @@ -200,7 +201,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing image.Save($"{path}/Opacity.png"); //shift background color towards forground color by the opacity amount - Rgba32 mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); + var mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); using (PixelAccessor sourcePixels = image.Lock()) { diff --git a/tests/ImageSharp.Tests/Drawing/LineTests.cs b/tests/ImageSharp.Tests/Drawing/LineTests.cs index d8c5c41d8b..d7eb0b6579 100644 --- a/tests/ImageSharp.Tests/Drawing/LineTests.cs +++ b/tests/ImageSharp.Tests/Drawing/LineTests.cs @@ -1,15 +1,18 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System.IO; using System.Numerics; -using SixLabors.ImageSharp.Drawing; -using SixLabors.ImageSharp.Drawing.Pens; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Drawing; +using SixLabors.ImageSharp.Processing.Drawing.Pens; + using Xunit; namespace SixLabors.ImageSharp.Tests.Drawing { + using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Overlays; + public class LineTests : FileTestBase { [Fact] diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs index a88a5b09cd..4713e63c25 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs @@ -1,13 +1,12 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using System.Numerics; -using SixLabors.ImageSharp; -using SixLabors.ImageSharp.Drawing; -using SixLabors.ImageSharp.Drawing.Brushes; -using SixLabors.ImageSharp.Drawing.Processors; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Primitives; +using SixLabors.ImageSharp.Processing.Drawing; +using SixLabors.ImageSharp.Processing.Drawing.Brushes; +using SixLabors.ImageSharp.Processing.Drawing.Processors; using SixLabors.Shapes; using Xunit; @@ -18,7 +17,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths GraphicsOptions noneDefault = new GraphicsOptions(); Rgba32 color = Rgba32.HotPink; SolidBrush brush = Brushes.Solid(Rgba32.HotPink); - IPath path = new SixLabors.Shapes.Path(new LinearLineSegment(new SixLabors.Primitives.PointF[] { + IPath path = new Path(new LinearLineSegment(new SixLabors.Primitives.PointF[] { new Vector2(10,10), new Vector2(20,10), new Vector2(20,10), @@ -28,7 +27,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsBrushAndPath() { - this.operations.Fill(brush, path); + this.operations.Fill(this.brush, this.path); var processor = this.Verify>(); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -39,28 +38,28 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths Polygon polygon = Assert.IsType(region.Shape); LinearLineSegment segments = Assert.IsType(polygon.LineSegments[0]); - Assert.Equal(brush, processor.Brush); + Assert.Equal(this.brush, processor.Brush); } [Fact] public void CorrectlySetsBrushPathOptions() { - this.operations.Fill(brush, path, noneDefault); + this.operations.Fill(this.brush, this.path, this.noneDefault); var processor = this.Verify>(); - Assert.Equal(noneDefault, processor.Options); + Assert.Equal(this.noneDefault, processor.Options); ShapeRegion region = Assert.IsType(processor.Region); Polygon polygon = Assert.IsType(region.Shape); LinearLineSegment segments = Assert.IsType(polygon.LineSegments[0]); - Assert.Equal(brush, processor.Brush); + Assert.Equal(this.brush, processor.Brush); } [Fact] public void CorrectlySetsColorAndPath() { - this.operations.Fill(color, path); + this.operations.Fill(this.color, this.path); var processor = this.Verify>(); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -70,23 +69,23 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths LinearLineSegment segments = Assert.IsType(polygon.LineSegments[0]); SolidBrush brush = Assert.IsType>(processor.Brush); - Assert.Equal(color, brush.Color); + Assert.Equal(this.color, brush.Color); } [Fact] public void CorrectlySetsColorPathAndOptions() { - this.operations.Fill(color, path, noneDefault); + this.operations.Fill(this.color, this.path, this.noneDefault); var processor = this.Verify>(); - Assert.Equal(noneDefault, processor.Options); + Assert.Equal(this.noneDefault, processor.Options); ShapeRegion region = Assert.IsType(processor.Region); Polygon polygon = Assert.IsType(region.Shape); LinearLineSegment segments = Assert.IsType(polygon.LineSegments[0]); SolidBrush brush = Assert.IsType>(processor.Brush); - Assert.Equal(color, brush.Color); + Assert.Equal(this.color, brush.Color); } } } diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs index e8fad9d125..526cf1b924 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs @@ -1,13 +1,12 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using System.Numerics; -using SixLabors.ImageSharp; -using SixLabors.ImageSharp.Drawing; -using SixLabors.ImageSharp.Drawing.Brushes; -using SixLabors.ImageSharp.Drawing.Processors; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Primitives; +using SixLabors.ImageSharp.Processing.Drawing; +using SixLabors.ImageSharp.Processing.Drawing.Brushes; +using SixLabors.ImageSharp.Processing.Drawing.Processors; using SixLabors.Shapes; using Xunit; @@ -18,13 +17,13 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths GraphicsOptions noneDefault = new GraphicsOptions(); Rgba32 color = Rgba32.HotPink; SolidBrush brush = Brushes.Solid(Rgba32.HotPink); - IPath path1 = new SixLabors.Shapes.Path(new LinearLineSegment(new SixLabors.Primitives.PointF[] { + IPath path1 = new Path(new LinearLineSegment(new SixLabors.Primitives.PointF[] { new Vector2(10,10), new Vector2(20,10), new Vector2(20,10), new Vector2(30,10), })); - IPath path2 = new SixLabors.Shapes.Path(new LinearLineSegment(new SixLabors.Primitives.PointF[] { + IPath path2 = new Path(new LinearLineSegment(new SixLabors.Primitives.PointF[] { new Vector2(10,10), new Vector2(20,10), new Vector2(20,10), @@ -35,15 +34,15 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths public FillPathCollection() { - this.pathCollection = new PathCollection(path1, path2); + this.pathCollection = new PathCollection(this.path1, this.path2); } [Fact] public void CorrectlySetsBrushAndPath() { - this.operations.Fill(brush, pathCollection); + this.operations.Fill(this.brush, this.pathCollection); - for (var i = 0; i < 2; i++) + for (int i = 0; i < 2; i++) { FillRegionProcessor processor = this.Verify>(i); @@ -55,35 +54,35 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths Polygon polygon = Assert.IsType(region.Shape); LinearLineSegment segments = Assert.IsType(polygon.LineSegments[0]); - Assert.Equal(brush, processor.Brush); + Assert.Equal(this.brush, processor.Brush); } } [Fact] public void CorrectlySetsBrushPathOptions() { - this.operations.Fill(brush, pathCollection, noneDefault); + this.operations.Fill(this.brush, this.pathCollection, this.noneDefault); - for (var i = 0; i < 2; i++) + for (int i = 0; i < 2; i++) { FillRegionProcessor processor = this.Verify>(i); - Assert.Equal(noneDefault, processor.Options); + Assert.Equal(this.noneDefault, processor.Options); ShapeRegion region = Assert.IsType(processor.Region); Polygon polygon = Assert.IsType(region.Shape); LinearLineSegment segments = Assert.IsType(polygon.LineSegments[0]); - Assert.Equal(brush, processor.Brush); + Assert.Equal(this.brush, processor.Brush); } } [Fact] public void CorrectlySetsColorAndPath() { - this.operations.Fill(color, pathCollection); + this.operations.Fill(this.color, this.pathCollection); - for (var i = 0; i < 2; i++) + for (int i = 0; i < 2; i++) { FillRegionProcessor processor = this.Verify>(i); @@ -94,27 +93,27 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths LinearLineSegment segments = Assert.IsType(polygon.LineSegments[0]); SolidBrush brush = Assert.IsType>(processor.Brush); - Assert.Equal(color, brush.Color); + Assert.Equal(this.color, brush.Color); } } [Fact] public void CorrectlySetsColorPathAndOptions() { - this.operations.Fill(color, pathCollection, noneDefault); + this.operations.Fill(this.color, this.pathCollection, this.noneDefault); - for (var i = 0; i < 2; i++) + for (int i = 0; i < 2; i++) { FillRegionProcessor processor = this.Verify>(i); - Assert.Equal(noneDefault, processor.Options); + Assert.Equal(this.noneDefault, processor.Options); ShapeRegion region = Assert.IsType(processor.Region); Polygon polygon = Assert.IsType(region.Shape); LinearLineSegment segments = Assert.IsType(polygon.LineSegments[0]); SolidBrush brush = Assert.IsType>(processor.Brush); - Assert.Equal(color, brush.Color); + Assert.Equal(this.color, brush.Color); } } } diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs index b390c31069..a1f083cf43 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs @@ -1,13 +1,12 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using System.Numerics; -using SixLabors.ImageSharp; -using SixLabors.ImageSharp.Drawing; -using SixLabors.ImageSharp.Drawing.Brushes; -using SixLabors.ImageSharp.Drawing.Processors; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Primitives; +using SixLabors.ImageSharp.Processing.Drawing; +using SixLabors.ImageSharp.Processing.Drawing.Brushes; +using SixLabors.ImageSharp.Processing.Drawing.Processors; using SixLabors.Shapes; using Xunit; @@ -18,7 +17,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths GraphicsOptions noneDefault = new GraphicsOptions(); Rgba32 color = Rgba32.HotPink; SolidBrush brush = Brushes.Solid(Rgba32.HotPink); - SixLabors.Primitives.PointF[] path = new SixLabors.Primitives.PointF[] { + SixLabors.Primitives.PointF[] path = { new Vector2(10,10), new Vector2(20,10), new Vector2(20,10), @@ -29,7 +28,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsBrushAndPath() { - this.operations.FillPolygon(brush, path); + this.operations.FillPolygon(this.brush, this.path); FillRegionProcessor processor = this.Verify>(); @@ -39,28 +38,28 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths Polygon polygon = Assert.IsType(region.Shape); LinearLineSegment segemnt = Assert.IsType(polygon.LineSegments[0]); - Assert.Equal(brush, processor.Brush); + Assert.Equal(this.brush, processor.Brush); } [Fact] public void CorrectlySetsBrushPathAndOptions() { - this.operations.FillPolygon(brush, path, noneDefault); + this.operations.FillPolygon(this.brush, this.path, this.noneDefault); FillRegionProcessor processor = this.Verify>(); - Assert.Equal(noneDefault, processor.Options); + Assert.Equal(this.noneDefault, processor.Options); ShapeRegion region = Assert.IsType(processor.Region); Polygon polygon = Assert.IsType(region.Shape); LinearLineSegment segemnt = Assert.IsType(polygon.LineSegments[0]); - Assert.Equal(brush, processor.Brush); + Assert.Equal(this.brush, processor.Brush); } [Fact] public void CorrectlySetsColorAndPath() { - this.operations.FillPolygon(color, path); + this.operations.FillPolygon(this.color, this.path); FillRegionProcessor processor = this.Verify>(); @@ -71,24 +70,24 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths LinearLineSegment segemnt = Assert.IsType(polygon.LineSegments[0]); SolidBrush brush = Assert.IsType>(processor.Brush); - Assert.Equal(color, brush.Color); + Assert.Equal(this.color, brush.Color); } [Fact] public void CorrectlySetsColorPathAndOptions() { - this.operations.FillPolygon(color, path, noneDefault); + this.operations.FillPolygon(this.color, this.path, this.noneDefault); FillRegionProcessor processor = this.Verify>(); - Assert.Equal(noneDefault, processor.Options); + Assert.Equal(this.noneDefault, processor.Options); ShapeRegion region = Assert.IsType(processor.Region); Polygon polygon = Assert.IsType(region.Shape); LinearLineSegment segemnt = Assert.IsType(polygon.LineSegments[0]); SolidBrush brush = Assert.IsType>(processor.Brush); - Assert.Equal(color, brush.Color); + Assert.Equal(this.color, brush.Color); } } } diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs index 05e6bb29b3..263eb9a9ca 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs @@ -1,11 +1,11 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; -using SixLabors.ImageSharp.Drawing; -using SixLabors.ImageSharp.Drawing.Brushes; -using SixLabors.ImageSharp.Drawing.Processors; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Primitives; +using SixLabors.ImageSharp.Processing.Drawing; +using SixLabors.ImageSharp.Processing.Drawing.Brushes; +using SixLabors.ImageSharp.Processing.Drawing.Processors; using Xunit; namespace SixLabors.ImageSharp.Tests.Drawing.Paths @@ -20,75 +20,75 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsBrushAndRectangle() { - this.operations.Fill(brush, rectangle); + this.operations.Fill(this.brush, this.rectangle); FillRegionProcessor processor = this.Verify>(); Assert.Equal(GraphicsOptions.Default, processor.Options); ShapeRegion region = Assert.IsType(processor.Region); - SixLabors.Shapes.RectangularePolygon rect = Assert.IsType(region.Shape); - Assert.Equal(rect.Location.X, rectangle.X); - Assert.Equal(rect.Location.Y, rectangle.Y); - Assert.Equal(rect.Size.Width, rectangle.Width); - Assert.Equal(rect.Size.Height, rectangle.Height); + Shapes.RectangularePolygon rect = Assert.IsType(region.Shape); + Assert.Equal(rect.Location.X, this.rectangle.X); + Assert.Equal(rect.Location.Y, this.rectangle.Y); + Assert.Equal(rect.Size.Width, this.rectangle.Width); + Assert.Equal(rect.Size.Height, this.rectangle.Height); - Assert.Equal(brush, processor.Brush); + Assert.Equal(this.brush, processor.Brush); } [Fact] public void CorrectlySetsBrushRectangleAndOptions() { - this.operations.Fill(brush, rectangle, noneDefault); + this.operations.Fill(this.brush, this.rectangle, this.noneDefault); FillRegionProcessor processor = this.Verify>(); - Assert.Equal(noneDefault, processor.Options); + Assert.Equal(this.noneDefault, processor.Options); ShapeRegion region = Assert.IsType(processor.Region); - SixLabors.Shapes.RectangularePolygon rect = Assert.IsType(region.Shape); - Assert.Equal(rect.Location.X, rectangle.X); - Assert.Equal(rect.Location.Y, rectangle.Y); - Assert.Equal(rect.Size.Width, rectangle.Width); - Assert.Equal(rect.Size.Height, rectangle.Height); + Shapes.RectangularePolygon rect = Assert.IsType(region.Shape); + Assert.Equal(rect.Location.X, this.rectangle.X); + Assert.Equal(rect.Location.Y, this.rectangle.Y); + Assert.Equal(rect.Size.Width, this.rectangle.Width); + Assert.Equal(rect.Size.Height, this.rectangle.Height); - Assert.Equal(brush, processor.Brush); + Assert.Equal(this.brush, processor.Brush); } [Fact] public void CorrectlySetsColorAndRectangle() { - this.operations.Fill(color, rectangle); + this.operations.Fill(this.color, this.rectangle); FillRegionProcessor processor = this.Verify>(); - + Assert.Equal(GraphicsOptions.Default, processor.Options); ShapeRegion region = Assert.IsType(processor.Region); - SixLabors.Shapes.RectangularePolygon rect = Assert.IsType(region.Shape); - Assert.Equal(rect.Location.X, rectangle.X); - Assert.Equal(rect.Location.Y, rectangle.Y); - Assert.Equal(rect.Size.Width, rectangle.Width); - Assert.Equal(rect.Size.Height, rectangle.Height); + Shapes.RectangularePolygon rect = Assert.IsType(region.Shape); + Assert.Equal(rect.Location.X, this.rectangle.X); + Assert.Equal(rect.Location.Y, this.rectangle.Y); + Assert.Equal(rect.Size.Width, this.rectangle.Width); + Assert.Equal(rect.Size.Height, this.rectangle.Height); SolidBrush brush = Assert.IsType>(processor.Brush); - Assert.Equal(color, brush.Color); + Assert.Equal(this.color, brush.Color); } [Fact] public void CorrectlySetsColorRectangleAndOptions() { - this.operations.Fill(color, rectangle, noneDefault); + this.operations.Fill(this.color, this.rectangle, this.noneDefault); FillRegionProcessor processor = this.Verify>(); - Assert.Equal(noneDefault, processor.Options); + Assert.Equal(this.noneDefault, processor.Options); ShapeRegion region = Assert.IsType(processor.Region); - SixLabors.Shapes.RectangularePolygon rect = Assert.IsType(region.Shape); - Assert.Equal(rect.Location.X, rectangle.X); - Assert.Equal(rect.Location.Y, rectangle.Y); - Assert.Equal(rect.Size.Width, rectangle.Width); - Assert.Equal(rect.Size.Height, rectangle.Height); + Shapes.RectangularePolygon rect = Assert.IsType(region.Shape); + Assert.Equal(rect.Location.X, this.rectangle.X); + Assert.Equal(rect.Location.Y, this.rectangle.Y); + Assert.Equal(rect.Size.Width, this.rectangle.Width); + Assert.Equal(rect.Size.Height, this.rectangle.Height); SolidBrush brush = Assert.IsType>(processor.Brush); - Assert.Equal(color, brush.Color); + Assert.Equal(this.color, brush.Color); } } } diff --git a/tests/ImageSharp.Tests/Drawing/Paths/ShapePathTests.cs b/tests/ImageSharp.Tests/Drawing/Paths/ShapePathTests.cs index 5d2e93e877..b474f6e47c 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/ShapePathTests.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/ShapePathTests.cs @@ -1,25 +1,10 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; -using System.Collections.Generic; -using System.Collections.Immutable; -using System.IO; -using System.Numerics; -using SixLabors.ImageSharp; -using SixLabors.ImageSharp.Drawing; -using SixLabors.ImageSharp.Drawing.Brushes; -using SixLabors.ImageSharp.Drawing.Pens; -using SixLabors.ImageSharp.Drawing.Processors; -using SixLabors.ImageSharp.Processing; -using Moq; -using SixLabors.Shapes; -using Xunit; - namespace SixLabors.ImageSharp.Tests.Drawing.Paths { public class ShapePathTests { - // TODO readd these back in + // TODO read these back in } } diff --git a/tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs b/tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs index 5ca09ad1d2..2a9ab3412e 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs @@ -1,13 +1,13 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using SixLabors.ImageSharp.Primitives; + namespace SixLabors.ImageSharp.Tests.Drawing.Paths { using System; using Moq; - - using SixLabors.ImageSharp.Drawing; using SixLabors.Primitives; using SixLabors.Shapes; @@ -40,7 +40,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths [Fact] public void ShapeRegionWithPathRetainsShape() { - ShapeRegion region = new ShapeRegion(this.pathMock.Object); + var region = new ShapeRegion(this.pathMock.Object); Assert.Equal(this.pathMock.Object, region.Shape); } @@ -48,7 +48,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths [Fact] public void ShapeRegionFromPathConvertsBoundsProxyToShape() { - ShapeRegion region = new ShapeRegion(this.pathMock.Object); + var region = new ShapeRegion(this.pathMock.Object); Assert.Equal(Math.Floor(this.bounds.Left), region.Bounds.Left); Assert.Equal(Math.Ceiling(this.bounds.Right), region.Bounds.Right); @@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths [Fact] public void ShapeRegionFromPathMaxIntersectionsProxyToShape() { - ShapeRegion region = new ShapeRegion(this.pathMock.Object); + var region = new ShapeRegion(this.pathMock.Object); int i = region.MaxIntersections; this.pathMock.Verify(x => x.MaxIntersections); @@ -69,7 +69,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths public void ShapeRegionFromPathScanYProxyToShape() { int yToScan = 10; - ShapeRegion region = new ShapeRegion(this.pathMock.Object); + var region = new ShapeRegion(this.pathMock.Object); this.pathMock .Setup( @@ -97,7 +97,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths public void ShapeRegionFromShapeScanYProxyToShape() { int yToScan = 10; - ShapeRegion region = new ShapeRegion(this.pathMock.Object); + var region = new ShapeRegion(this.pathMock.Object); this.pathMock .Setup( @@ -124,7 +124,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths [Fact] public void ShapeRegionFromShapeConvertsBoundsProxyToShape() { - ShapeRegion region = new ShapeRegion(this.pathMock.Object); + var region = new ShapeRegion(this.pathMock.Object); Assert.Equal(Math.Floor(this.bounds.Left), region.Bounds.Left); Assert.Equal(Math.Ceiling(this.bounds.Right), region.Bounds.Right); @@ -135,7 +135,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths [Fact] public void ShapeRegionFromShapeMaxIntersectionsProxyToShape() { - ShapeRegion region = new ShapeRegion(this.pathMock.Object); + var region = new ShapeRegion(this.pathMock.Object); int i = region.MaxIntersections; this.pathMock.Verify(x => x.MaxIntersections); diff --git a/tests/ImageSharp.Tests/Drawing/PolygonTests.cs b/tests/ImageSharp.Tests/Drawing/PolygonTests.cs index a43f14eb71..f6d9bf2131 100644 --- a/tests/ImageSharp.Tests/Drawing/PolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/PolygonTests.cs @@ -1,14 +1,13 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; -using System.Diagnostics.CodeAnalysis; -using System.IO; using System.Numerics; -using SixLabors.ImageSharp.Drawing; + using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Tests.Drawing; using SixLabors.Primitives; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Drawing; +using SixLabors.ImageSharp.Processing.Overlays; using Xunit; namespace SixLabors.ImageSharp.Tests.Drawing diff --git a/tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs b/tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs index 52668cc56c..4a87ad189d 100644 --- a/tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs +++ b/tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs @@ -1,15 +1,16 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System.IO; -using System.Linq; -using SixLabors.ImageSharp.Drawing.Brushes; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Drawing; +using SixLabors.ImageSharp.Processing.Drawing.Brushes; using SixLabors.Primitives; using Xunit; namespace SixLabors.ImageSharp.Tests { + using SixLabors.ImageSharp.Processing; + public class RecolorImageTest : FileTestBase { [Fact] @@ -17,7 +18,7 @@ namespace SixLabors.ImageSharp.Tests { string path = TestEnvironment.CreateOutputDirectory("Drawing", "RecolorImage"); - RecolorBrush brush = new RecolorBrush(Rgba32.Yellow, Rgba32.HotPink, 0.2f); + var brush = new RecolorBrush(Rgba32.Yellow, Rgba32.HotPink, 0.2f); foreach (TestFile file in Files) { @@ -34,7 +35,7 @@ namespace SixLabors.ImageSharp.Tests { string path = TestEnvironment.CreateOutputDirectory("Drawing", "RecolorImage"); - RecolorBrush brush = new RecolorBrush(Rgba32.Yellow, Rgba32.HotPink, 0.2f); + var brush = new RecolorBrush(Rgba32.Yellow, Rgba32.HotPink, 0.2f); foreach (TestFile file in Files) { diff --git a/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs b/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs index 70badd34c5..7c75c2c443 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs @@ -1,14 +1,17 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System.IO; using System.Numerics; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Drawing; using SixLabors.Shapes; using Xunit; namespace SixLabors.ImageSharp.Tests.Drawing { + using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Overlays; + [GroupOutput("Drawing")] public class SolidBezierTests { @@ -17,7 +20,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing public void FilledBezier(TestImageProvider provider) where TPixel : struct, IPixel { - Primitives.PointF[] simplePath = { + SixLabors.Primitives.PointF[] simplePath = { new Vector2(10, 400), new Vector2(30, 10), new Vector2(240, 30), @@ -29,7 +32,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing using (Image image = provider.GetImage()) { - + image.Mutate(x => x .BackgroundColor(blue) .Fill(hotPink, new Polygon(new CubicBezierLineSegment(simplePath)))); @@ -43,14 +46,14 @@ namespace SixLabors.ImageSharp.Tests.Drawing public void OverlayByFilledPolygonOpacity(TestImageProvider provider) where TPixel : struct, IPixel { - Primitives.PointF[] simplePath = { + SixLabors.Primitives.PointF[] simplePath = { new Vector2(10, 400), new Vector2(30, 10), new Vector2(240, 30), new Vector2(300, 400) }; - Rgba32 color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150); + var color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150); using (var image = provider.GetImage() as Image) { diff --git a/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs index e1849b0d01..39a7bac53d 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs @@ -1,16 +1,18 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System.IO; using System.Numerics; -using SixLabors.ImageSharp.Drawing; + using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Tests.Drawing; +using SixLabors.ImageSharp.Processing.Drawing; using SixLabors.Shapes; using Xunit; namespace SixLabors.ImageSharp.Tests.Drawing { + using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Overlays; + public class SolidComplexPolygonTests : FileTestBase { [Fact] diff --git a/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs index be7c8adb08..6eeed144c9 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs @@ -2,31 +2,31 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Diagnostics.CodeAnalysis; -using System.IO; using System.Numerics; -using SixLabors.ImageSharp.Drawing; -using SixLabors.ImageSharp.Drawing.Brushes; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Tests.Drawing; +using SixLabors.ImageSharp.Processing.Drawing; using SixLabors.Shapes; using Xunit; namespace SixLabors.ImageSharp.Tests.Drawing { + using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Drawing.Brushes; + using SixLabors.ImageSharp.Processing.Overlays; + public class SolidPolygonTests : FileTestBase { [Fact] public void ImageShouldBeOverlayedByFilledPolygon() { string path = TestEnvironment.CreateOutputDirectory("Drawing", "FilledPolygons"); - SixLabors.Primitives.PointF[] simplePath = new SixLabors.Primitives.PointF[] { + SixLabors.Primitives.PointF[] simplePath = { new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) }; - using (Image image = new Image(500, 500)) + using (var image = new Image(500, 500)) { image.Mutate(x => x .FillPolygon(Rgba32.HotPink, simplePath, new GraphicsOptions(true))); @@ -43,13 +43,13 @@ namespace SixLabors.ImageSharp.Tests.Drawing public void ImageShouldBeOverlayedByFilledPolygonWithPattern() { string path = TestEnvironment.CreateOutputDirectory("Drawing", "FilledPolygons"); - SixLabors.Primitives.PointF[] simplePath = new SixLabors.Primitives.PointF[] { + var simplePath = new SixLabors.Primitives.PointF[] { new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) }; - using (Image image = new Image(500, 500)) + using (var image = new Image(500, 500)) { image.Mutate(x => x .FillPolygon(Brushes.Horizontal(Rgba32.HotPink), simplePath, new GraphicsOptions(true))); @@ -66,13 +66,13 @@ namespace SixLabors.ImageSharp.Tests.Drawing public void ImageShouldBeOverlayedByFilledPolygonNoAntialias() { string path = TestEnvironment.CreateOutputDirectory("Drawing", "FilledPolygons"); - SixLabors.Primitives.PointF[] simplePath = new SixLabors.Primitives.PointF[] { + var simplePath = new SixLabors.Primitives.PointF[] { new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) }; - using (Image image = new Image(500, 500)) + using (var image = new Image(500, 500)) { image.Mutate(x => x .BackgroundColor(Rgba32.Blue) @@ -96,16 +96,16 @@ namespace SixLabors.ImageSharp.Tests.Drawing public void ImageShouldBeOverlayedByFilledPolygonImage() { string path = TestEnvironment.CreateOutputDirectory("Drawing", "FilledPolygons"); - SixLabors.Primitives.PointF[] simplePath = new SixLabors.Primitives.PointF[] { + var simplePath = new SixLabors.Primitives.PointF[] { new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) }; using (Image brushImage = TestFile.Create(TestImages.Bmp.Car).CreateImage()) - using (Image image = new Image(500, 500)) + using (var image = new Image(500, 500)) { - ImageBrush brush = new ImageBrush(brushImage); + var brush = new ImageBrush(brushImage); image.Mutate(x => x .BackgroundColor(Rgba32.Blue) @@ -118,14 +118,14 @@ namespace SixLabors.ImageSharp.Tests.Drawing public void ImageShouldBeOverlayedByFilledPolygonOpacity() { string path = TestEnvironment.CreateOutputDirectory("Drawing", "FilledPolygons"); - SixLabors.Primitives.PointF[] simplePath = new SixLabors.Primitives.PointF[] { + var simplePath = new SixLabors.Primitives.PointF[] { new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) }; - Rgba32 color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150); + var color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150); - using (Image image = new Image(500, 500)) + using (var image = new Image(500, 500)) { image.Mutate(x => x .BackgroundColor(Rgba32.Blue) @@ -133,7 +133,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing image.Save($"{path}/Opacity.png"); //shift background color towards forground color by the opacity amount - Rgba32 mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); + var mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); using (PixelAccessor sourcePixels = image.Lock()) { @@ -147,7 +147,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing { string path = TestEnvironment.CreateOutputDirectory("Drawing", "FilledPolygons"); - using (Image image = new Image(500, 500)) + using (var image = new Image(500, 500)) { image.Mutate(x => x .BackgroundColor(Rgba32.Blue) @@ -174,7 +174,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing { string path = TestEnvironment.CreateOutputDirectory("Drawing", "FilledPolygons"); - using (Image image = new Image(100, 100)) + using (var image = new Image(100, 100)) { image.Mutate(x => x .BackgroundColor(Rgba32.Blue) @@ -195,9 +195,9 @@ namespace SixLabors.ImageSharp.Tests.Drawing { string path = TestEnvironment.CreateOutputDirectory("Drawing", "FilledPolygons"); - Configuration config = Configuration.CreateDefaultInstance(); + var config = Configuration.CreateDefaultInstance(); config.ParallelOptions.MaxDegreeOfParallelism = 1; - using (Image image = new Image(config, 100, 100)) + using (var image = new Image(config, 100, 100)) { image.Mutate(x => x .BackgroundColor(Rgba32.Blue) @@ -211,9 +211,9 @@ namespace SixLabors.ImageSharp.Tests.Drawing { string path = TestEnvironment.CreateOutputDirectory("Drawing", "FilledPolygons"); - Configuration config = Configuration.CreateDefaultInstance(); + var config = Configuration.CreateDefaultInstance(); config.ParallelOptions.MaxDegreeOfParallelism = 1; - using (Image image = new Image(config, 100, 100)) + using (var image = new Image(config, 100, 100)) { image.Mutate(x => x .BackgroundColor(Rgba32.Blue) @@ -228,9 +228,9 @@ namespace SixLabors.ImageSharp.Tests.Drawing { string path = TestEnvironment.CreateOutputDirectory("Drawing", "FilledPolygons"); - Configuration config = Configuration.CreateDefaultInstance(); + var config = Configuration.CreateDefaultInstance(); config.ParallelOptions.MaxDegreeOfParallelism = 1; - using (Image image = new Image(config, 200, 200)) + using (var image = new Image(config, 200, 200)) { image.Mutate(x => x .Fill(Rgba32.Blue) diff --git a/tests/ImageSharp.Tests/Drawing/Text/DrawText.Path.cs b/tests/ImageSharp.Tests/Drawing/Text/DrawText.Path.cs index 3f138248eb..85503a5524 100644 --- a/tests/ImageSharp.Tests/Drawing/Text/DrawText.Path.cs +++ b/tests/ImageSharp.Tests/Drawing/Text/DrawText.Path.cs @@ -1,17 +1,15 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using System.Numerics; -using SixLabors.ImageSharp.Drawing; -using SixLabors.ImageSharp.Drawing.Brushes; -using SixLabors.ImageSharp.Drawing.Pens; -using SixLabors.ImageSharp.Drawing.Processors; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Tests.Drawing.Paths; using SixLabors.Fonts; +using SixLabors.ImageSharp.Processing.Drawing.Brushes; +using SixLabors.ImageSharp.Processing.Drawing.Processors; +using SixLabors.ImageSharp.Processing.Text; using SixLabors.Shapes; using Xunit; +using SixLabors.ImageSharp.Processing.Drawing.Pens; namespace SixLabors.ImageSharp.Tests.Drawing.Text { @@ -43,7 +41,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text this.Font, Brushes.Solid(Rgba32.Red), null, - path, + this.path, new TextGraphicsOptions(true)); this.Verify>(0); @@ -54,7 +52,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text [Fact] public void FillsForEachACharachterWhenBrushSetAndNotPenDefaultOptions() { - this.operations.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), null, path); + this.operations.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), null, this.path); this.Verify>(0); this.Verify>(1); @@ -64,7 +62,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text [Fact] public void FillsForEachACharachterWhenBrushSet() { - this.operations.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), path, new TextGraphicsOptions(true)); + this.operations.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), this.path, new TextGraphicsOptions(true)); this.Verify>(0); this.Verify>(1); @@ -74,7 +72,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text [Fact] public void FillsForEachACharachterWhenBrushSetDefaultOptions() { - this.operations.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), path); + this.operations.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), this.path); this.Verify>(0); this.Verify>(1); @@ -84,7 +82,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text [Fact] public void FillsForEachACharachterWhenColorSet() { - this.operations.DrawText("123", this.Font, Rgba32.Red, path, new TextGraphicsOptions(true)); + this.operations.DrawText("123", this.Font, Rgba32.Red, this.path, new TextGraphicsOptions(true)); var processor = this.Verify>(0); this.Verify>(1); @@ -97,9 +95,9 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text [Fact] public void FillsForEachACharachterWhenColorSetDefaultOptions() { - this.operations.DrawText("123", this.Font, Rgba32.Red, path); + this.operations.DrawText("123", this.Font, Rgba32.Red, this.path); - var processor = this.Verify>(0); + FillRegionProcessor processor = this.Verify>(0); this.Verify>(1); this.Verify>(2); @@ -115,7 +113,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text this.Font, null, Pens.Dash(Rgba32.Red, 1), - path, + this.path, new TextGraphicsOptions(true)); var processor = this.Verify>(0); @@ -126,7 +124,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text [Fact] public void DrawForEachACharachterWhenPenSetAndNotBrushDefaultOptions() { - this.operations.DrawText("123", this.Font, null, Pens.Dash(Rgba32.Red, 1), path); + this.operations.DrawText("123", this.Font, null, Pens.Dash(Rgba32.Red, 1), this.path); var processor = this.Verify>(0); this.Verify>(1); @@ -136,7 +134,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text [Fact] public void DrawForEachACharachterWhenPenSet() { - this.operations.DrawText("123", this.Font, Pens.Dash(Rgba32.Red, 1), path, new TextGraphicsOptions(true)); + this.operations.DrawText("123", this.Font, Pens.Dash(Rgba32.Red, 1), this.path, new TextGraphicsOptions(true)); var processor = this.Verify>(0); this.Verify>(1); @@ -146,9 +144,9 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text [Fact] public void DrawForEachACharachterWhenPenSetDefaultOptions() { - this.operations.DrawText("123", this.Font, Pens.Dash(Rgba32.Red, 1), path); + this.operations.DrawText("123", this.Font, Pens.Dash(Rgba32.Red, 1), this.path); - var processor = this.Verify>(0); + FillRegionProcessor processor = this.Verify>(0); this.Verify>(1); this.Verify>(2); } @@ -161,7 +159,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), - path, + this.path, new TextGraphicsOptions(true)); var processor = this.Verify>(0); @@ -175,7 +173,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text [Fact] public void DrawForEachACharachterWhenPenSetAndFillFroEachWhenBrushSetDefaultOptions() { - this.operations.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), path); + this.operations.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), this.path); var processor = this.Verify>(0); this.Verify>(1); @@ -193,7 +191,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), - path, + this.path, new TextGraphicsOptions(true)); var processor = this.Verify>(0); @@ -203,7 +201,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text [Fact] public void BrushAppliesBeforPenDefaultOptions() { - this.operations.DrawText("1", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), path); + this.operations.DrawText("1", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), this.path); var processor = this.Verify>(0); this.Verify>(1); diff --git a/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs b/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs index d9fe1a76db..058ce6f95e 100644 --- a/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs +++ b/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs @@ -1,15 +1,13 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using System.Numerics; -using SixLabors.ImageSharp.Drawing; -using SixLabors.ImageSharp.Drawing.Brushes; -using SixLabors.ImageSharp.Drawing.Pens; -using SixLabors.ImageSharp.Drawing.Processors; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Tests.Drawing.Paths; using SixLabors.Fonts; +using SixLabors.ImageSharp.Processing.Drawing.Brushes; +using SixLabors.ImageSharp.Processing.Drawing.Pens; +using SixLabors.ImageSharp.Processing.Drawing.Processors; +using SixLabors.ImageSharp.Processing.Text; using SixLabors.Shapes; using Xunit; @@ -187,7 +185,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text } [Fact] - public void BrushAppliesBeforPen() + public void BrushAppliesBeforePen() { this.operations.DrawText( "1", diff --git a/tests/ImageSharp.Tests/Drawing/Text/OutputText.cs b/tests/ImageSharp.Tests/Drawing/Text/OutputText.cs index 079510c33a..ec05b64ab1 100644 --- a/tests/ImageSharp.Tests/Drawing/Text/OutputText.cs +++ b/tests/ImageSharp.Tests/Drawing/Text/OutputText.cs @@ -1,19 +1,14 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; -using System.Collections.Generic; -using System.IO; using System.Numerics; -using SixLabors.ImageSharp; -using SixLabors.ImageSharp.Drawing; -using SixLabors.ImageSharp.Drawing.Brushes; -using SixLabors.ImageSharp.Drawing.Pens; -using SixLabors.ImageSharp.Drawing.Processors; + using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.Fonts; -using SixLabors.Shapes; +using SixLabors.ImageSharp.Processing.Drawing; +using SixLabors.ImageSharp.Processing.Text; + using Xunit; namespace SixLabors.ImageSharp.Tests.Drawing.Text @@ -26,14 +21,14 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text public OutputText() { this.FontCollection = new FontCollection(); - this.Font = FontCollection.Install(TestFontUtilities.GetPath("SixLaborsSampleAB.woff")).CreateFont(12); + this.Font = this.FontCollection.Install(TestFontUtilities.GetPath("SixLaborsSampleAB.woff")).CreateFont(12); } [Fact] public void DrawAB() { //draws 2 overlapping triangle glyphs twice 1 set on each line - using (Image img = new Image(100, 200)) + using (var img = new Image(100, 200)) { img.Mutate(x => x.Fill(Rgba32.DarkBlue) .DrawText("AB\nAB", new Font(this.Font, 50), Rgba32.Red, new Vector2(0, 0))); diff --git a/tests/ImageSharp.Tests/Drawing/Text/TextGraphicsOptionsTests.cs b/tests/ImageSharp.Tests/Drawing/Text/TextGraphicsOptionsTests.cs index 975622e43d..d710229ff1 100644 --- a/tests/ImageSharp.Tests/Drawing/Text/TextGraphicsOptionsTests.cs +++ b/tests/ImageSharp.Tests/Drawing/Text/TextGraphicsOptionsTests.cs @@ -1,13 +1,8 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; -using System.Collections.Generic; -using System.Linq; -using System.Numerics; -using System.Threading.Tasks; -using SixLabors.ImageSharp.Drawing; -using SixLabors.Fonts; +using SixLabors.ImageSharp.Processing.Text; + using Xunit; namespace SixLabors.ImageSharp.Tests.Drawing.Text @@ -17,7 +12,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text [Fact] public void ExplicitCastOfGraphicsOptions() { - GraphicsOptions opt = new GraphicsOptions(false) + var opt = new GraphicsOptions(false) { AntialiasSubpixelDepth = 99 }; @@ -31,12 +26,12 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text [Fact] public void ImplicitCastToGraphicsOptions() { - TextGraphicsOptions textOptions = new TextGraphicsOptions(false) + var textOptions = new TextGraphicsOptions(false) { AntialiasSubpixelDepth = 99 }; - GraphicsOptions opt = (GraphicsOptions)textOptions; + var opt = (GraphicsOptions)textOptions; Assert.False(opt.Antialias); Assert.Equal(99, opt.AntialiasSubpixelDepth); diff --git a/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs b/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs index db1e7903de..cc2143afe1 100644 --- a/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs +++ b/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs @@ -3,10 +3,11 @@ using System.Collections.Generic; using System.Linq; -using SixLabors.ImageSharp.Helpers; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Tests diff --git a/tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs index 3a5fbe8387..aed68f76b5 100644 --- a/tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs @@ -9,6 +9,7 @@ using Xunit; namespace SixLabors.ImageSharp.Tests { + using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using Xunit.Abstractions; diff --git a/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs b/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs index 22a811feee..b78a8083e2 100644 --- a/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs +++ b/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs @@ -14,6 +14,9 @@ namespace SixLabors.ImageSharp.Tests { using System; + using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Quantization; + public class GeneralFormatTests : FileTestBase { [Theory] @@ -71,7 +74,7 @@ namespace SixLabors.ImageSharp.Tests { using (FileStream output = File.OpenWrite($"{path}/Octree-{file.FileName}")) { - image.Mutate(x => x.Quantize(Quantization.Octree)); + image.Mutate(x => x.Quantize(QuantizationMode.Octree)); image.Save(output, mimeType); } @@ -81,7 +84,7 @@ namespace SixLabors.ImageSharp.Tests { using (FileStream output = File.OpenWrite($"{path}/Wu-{file.FileName}")) { - image.Mutate(x => x.Quantize(Quantization.Wu)); + image.Mutate(x => x.Quantize(QuantizationMode.Wu)); image.Save(output, mimeType); } } @@ -90,7 +93,7 @@ namespace SixLabors.ImageSharp.Tests { using (FileStream output = File.OpenWrite($"{path}/Palette-{file.FileName}")) { - image.Mutate(x => x.Quantize(Quantization.Palette)); + image.Mutate(x => x.Quantize(QuantizationMode.Palette)); image.Save(output, mimeType); } } diff --git a/tests/ImageSharp.Tests/Formats/Jpg/GenericBlock8x8Tests.cs b/tests/ImageSharp.Tests/Formats/Jpg/GenericBlock8x8Tests.cs index 193e26fcbd..31c95fae6c 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/GenericBlock8x8Tests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/GenericBlock8x8Tests.cs @@ -2,12 +2,9 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg { using System; - using System.Numerics; using SixLabors.ImageSharp.Formats.Jpeg.Common; - using SixLabors.ImageSharp.Helpers; using SixLabors.ImageSharp.PixelFormats; - using SixLabors.Primitives; using Xunit; diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs index bf6b1f4ab2..70a35f182a 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs @@ -190,7 +190,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg [MemberData(nameof(CommonConversionData))] public void ConvertFromGrayScale(int inputBufferLength, int resultBufferLength, int seed) { - var converter = JpegColorConverter.GetConverter(JpegColorSpace.GrayScale); + var converter = JpegColorConverter.GetConverter(JpegColorSpace.Grayscale); JpegColorConverter.ComponentValues values = CreateRandomValues(1, inputBufferLength, seed); Vector4[] result = new Vector4[resultBufferLength]; diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs index cc030bbf7c..ec34691531 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs @@ -13,6 +13,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg using SixLabors.ImageSharp.Formats.Bmp; using SixLabors.ImageSharp.Formats.Jpeg; using SixLabors.ImageSharp.PixelFormats; + using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs; using SixLabors.Primitives; diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs index 6652db577c..4eca62cab0 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs @@ -2,6 +2,9 @@ // Licensed under the Apache License, Version 2.0. // ReSharper disable InconsistentNaming + +using SixLabors.ImageSharp.PixelFormats; + namespace SixLabors.ImageSharp.Tests.Formats.Jpg { using System; diff --git a/tests/ImageSharp.Tests/Formats/Jpg/ParseStreamTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/ParseStreamTests.cs index e56e912074..eb8ee90f9c 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/ParseStreamTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/ParseStreamTests.cs @@ -25,7 +25,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg [Theory] [InlineData(TestImages.Jpeg.Baseline.Testorig420, JpegColorSpace.YCbCr)] - [InlineData(TestImages.Jpeg.Baseline.Jpeg400, JpegColorSpace.GrayScale)] + [InlineData(TestImages.Jpeg.Baseline.Jpeg400, JpegColorSpace.Grayscale)] [InlineData(TestImages.Jpeg.Baseline.Ycck, JpegColorSpace.Ycck)] [InlineData(TestImages.Jpeg.Baseline.Cmyk, JpegColorSpace.Cmyk)] public void ColorSpace_IsDeducedCorrectly(string imageFile, object expectedColorSpaceValue) diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs index 9e287eb2d7..30f0088861 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs @@ -1,3 +1,5 @@ +using SixLabors.ImageSharp.PixelFormats; + namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils { using System; diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.SpectralData.cs b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.SpectralData.cs index 5a4db87b9b..a353b288ab 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.SpectralData.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.SpectralData.cs @@ -1,3 +1,5 @@ +using SixLabors.ImageSharp.PixelFormats; + namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils { using System; diff --git a/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs index 0010bb41d3..7f983e1e42 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs @@ -1,20 +1,18 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System.Collections.Generic; using System.IO; using System.Linq; -using System.Threading.Tasks; + using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats.Png; -using SixLabors.ImageSharp.IO; using SixLabors.ImageSharp.PixelFormats; using Xunit; // ReSharper disable InconsistentNaming namespace SixLabors.ImageSharp.Tests { - using SixLabors.ImageSharp.Quantizers; + using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; public class PngEncoderTests diff --git a/tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs index fc17df93d1..e7fd21d963 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs @@ -10,6 +10,9 @@ using SixLabors.ImageSharp.Formats.Png; namespace SixLabors.ImageSharp.Tests.Formats.Png { + using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Transforms; + public class PngSmokeTests { [Theory] diff --git a/tests/ImageSharp.Tests/Image/ImageLoadTests.cs b/tests/ImageSharp.Tests/Image/ImageLoadTests.cs index 97274e98b3..35d6b57226 100644 --- a/tests/ImageSharp.Tests/Image/ImageLoadTests.cs +++ b/tests/ImageSharp.Tests/Image/ImageLoadTests.cs @@ -8,6 +8,7 @@ using SixLabors.ImageSharp.IO; using Moq; using Xunit; using SixLabors.ImageSharp.Advanced; +using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Tests { diff --git a/tests/ImageSharp.Tests/Image/ImageProcessingContextTests.cs b/tests/ImageSharp.Tests/Image/ImageProcessingContextTests.cs index f8f7b6758a..4e149da503 100644 --- a/tests/ImageSharp.Tests/Image/ImageProcessingContextTests.cs +++ b/tests/ImageSharp.Tests/Image/ImageProcessingContextTests.cs @@ -1,11 +1,17 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +//using SixLabors.ImageSharp.Processing; + +using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; using Xunit; namespace SixLabors.ImageSharp.Tests { + using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Transforms; + public class ImageProcessingContextTests { [Fact] diff --git a/tests/ImageSharp.Tests/Image/ImageRotationTests.cs b/tests/ImageSharp.Tests/Image/ImageRotationTests.cs index 73c2f78f40..8310d67e83 100644 --- a/tests/ImageSharp.Tests/Image/ImageRotationTests.cs +++ b/tests/ImageSharp.Tests/Image/ImageRotationTests.cs @@ -1,12 +1,15 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Helpers; +using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; using Xunit; namespace SixLabors.ImageSharp.Tests { + using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Transforms; + public class ImageRotationTests { [Fact] diff --git a/tests/ImageSharp.Tests/ImageInfoTests.cs b/tests/ImageSharp.Tests/ImageInfoTests.cs new file mode 100644 index 0000000000..91f6804c0f --- /dev/null +++ b/tests/ImageSharp.Tests/ImageInfoTests.cs @@ -0,0 +1,34 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.MetaData; +using SixLabors.Primitives; + +using Xunit; + +namespace SixLabors.ImageSharp.Tests +{ + public class ImageInfoTests + { + [Fact] + public void ImageInfoInitializesCorrectly() + { + const int Width = 50; + const int Height = 60; + var size = new Size(Width, Height); + var rectangle = new Rectangle(0, 0, Width, Height); + var pixelType = new PixelTypeInfo(8); + var meta = new ImageMetaData(); + + var info = new ImageInfo(pixelType, Width, Height, meta); + + Assert.Equal(pixelType, info.PixelType); + Assert.Equal(Width, info.Width); + Assert.Equal(Height, info.Height); + Assert.Equal(size, info.Size()); + Assert.Equal(rectangle, info.Bounds()); + Assert.Equal(meta, info.MetaData); + } + } +} diff --git a/tests/ImageSharp.Tests/ImageOperationTests.cs b/tests/ImageSharp.Tests/ImageOperationTests.cs index a5d6d2eb96..61705fe4e6 100644 --- a/tests/ImageSharp.Tests/ImageOperationTests.cs +++ b/tests/ImageSharp.Tests/ImageOperationTests.cs @@ -2,15 +2,14 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Collections.Generic; -using System.IO; using System.Linq; -using SixLabors.ImageSharp.Formats; -using SixLabors.ImageSharp.IO; -using SixLabors.ImageSharp.PixelFormats; + using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors; using Moq; -using SixLabors.Primitives; + +using SixLabors.ImageSharp.PixelFormats; + using Xunit; namespace SixLabors.ImageSharp.Tests @@ -42,7 +41,7 @@ namespace SixLabors.ImageSharp.Tests this.image.Mutate(x => x.ApplyProcessor(this.processor)); Assert.True(this.provider.HasCreated(this.image)); - Assert.Contains(this.processor, this.provider.AppliedOperations(this.image).Select(x=>x.Processor)); + Assert.Contains(this.processor, this.provider.AppliedOperations(this.image).Select(x => x.Processor)); } [Fact] diff --git a/tests/ImageSharp.Tests/Issues/Issue412.cs b/tests/ImageSharp.Tests/Issues/Issue412.cs index b77112ba68..f48696cd9a 100644 --- a/tests/ImageSharp.Tests/Issues/Issue412.cs +++ b/tests/ImageSharp.Tests/Issues/Issue412.cs @@ -1,18 +1,18 @@ -using System; -using System.Collections.Generic; -using System.Text; -using SixLabors.Primitives; -using SixLabors.ImageSharp.Advanced; +using SixLabors.Primitives; + using Xunit; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Drawing; namespace SixLabors.ImageSharp.Tests.Issues { + using SixLabors.ImageSharp.Processing; + public class Issue412 { [Theory] [WithBlankImages(40, 30, PixelTypes.Rgba32)] - public void AllPixelsExpectedToBeRedWhenAntialisedDisabled(TestImageProvider provider) where TPixel : struct, IPixel + public void AllPixelsExpectedToBeRedWhenAntialiasedDisabled(TestImageProvider provider) where TPixel : struct, IPixel { using (var image = provider.GetImage()) { diff --git a/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs b/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs index c73ce96313..11cb861578 100644 --- a/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs +++ b/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs @@ -2,6 +2,9 @@ // Licensed under the Apache License, Version 2.0. // ReSharper disable InconsistentNaming + +using SixLabors.ImageSharp.PixelFormats; + namespace SixLabors.ImageSharp.Tests.Memory { using System; diff --git a/tests/ImageSharp.Tests/Memory/Fast2DArrayTests.cs b/tests/ImageSharp.Tests/Memory/Fast2DArrayTests.cs deleted file mode 100644 index a5364db721..0000000000 --- a/tests/ImageSharp.Tests/Memory/Fast2DArrayTests.cs +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -namespace SixLabors.ImageSharp.Tests.Memory -{ - using System; - - using SixLabors.ImageSharp.Memory; - - using Xunit; - - public class Fast2DArrayTests - { - private static readonly float[,] FloydSteinbergMatrix = - { - { 0, 0, 7 }, - { 3, 5, 1 } - }; - - [Fact] - public void Fast2DArrayThrowsOnNullInitializer() - { - Assert.Throws(() => - { - var fast = new Fast2DArray(null); - }); - } - - [Fact] - public void Fast2DArrayThrowsOnEmptyZeroWidth() - { - Assert.Throws(() => - { - var fast = new Fast2DArray(0, 10); - }); - } - - [Fact] - public void Fast2DArrayThrowsOnEmptyZeroHeight() - { - Assert.Throws(() => - { - var fast = new Fast2DArray(10, 0); - }); - } - - [Fact] - public void Fast2DArrayThrowsOnEmptyInitializer() - { - Assert.Throws(() => - { - var fast = new Fast2DArray(new float[0, 0]); - }); - } - - [Fact] - public void Fast2DArrayReturnsCorrectDimensions() - { - var fast = new Fast2DArray(FloydSteinbergMatrix); - Assert.True(fast.Width == FloydSteinbergMatrix.GetLength(1)); - Assert.True(fast.Height == FloydSteinbergMatrix.GetLength(0)); - } - - [Fact] - public void Fast2DArrayGetReturnsCorrectResults() - { - Fast2DArray fast = FloydSteinbergMatrix; - - for (int row = 0; row < fast.Height; row++) - { - for (int column = 0; column < fast.Width; column++) - { - Assert.True(Math.Abs(fast[row, column] - FloydSteinbergMatrix[row, column]) < Constants.Epsilon); - } - } - } - - [Fact] - public void Fast2DArrayGetSetReturnsCorrectResults() - { - var fast = new Fast2DArray(4, 4); - const float Val = 5F; - - fast[3, 3] = Val; - - Assert.True(Math.Abs(Val - fast[3, 3]) < Constants.Epsilon); - } - } -} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.MatrixTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.MatrixTests.cs index 437c223fa9..f01a5ef96d 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.MatrixTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.MatrixTests.cs @@ -8,6 +8,8 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Icc { + using SixLabors.ImageSharp.Primitives; + public class IccDataWriterMatrixTests { [Theory] @@ -35,8 +37,8 @@ namespace SixLabors.ImageSharp.Tests.Icc } [Theory] - [MemberData(nameof(IccTestDataMatrix.Matrix2D_Fast2DArrayTestData), MemberType = typeof(IccTestDataMatrix))] - internal void WriteMatrix2D_Fast2DArray(byte[] expected, int xCount, int yCount, bool isSingle, Fast2DArray data) + [MemberData(nameof(IccTestDataMatrix.Matrix2D_DenseMatrixTestData), MemberType = typeof(IccTestDataMatrix))] + internal void WriteMatrix2D_DenseMatrix(byte[] expected, int xCount, int yCount, bool isSingle, DenseMatrix data) { IccDataWriter writer = CreateWriter(); diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs index c0039bb37c..7a942246e3 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs @@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats { public partial class PixelOperationsTests { - public class Rgba32 : PixelOperationsTests + public class Rgba32 : PixelOperationsTests { public Rgba32(ITestOutputHelper output) : base(output) @@ -25,19 +25,19 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats [Fact] public void IsSpecialImplementation() { - Assert.IsType(PixelOperations.Instance); + Assert.IsType(PixelOperations.Instance); } [Fact] public void ToVector4SimdAligned() { - ImageSharp.Rgba32[] source = CreatePixelTestData(64); + ImageSharp.PixelFormats.Rgba32[] source = CreatePixelTestData(64); Vector4[] expected = CreateExpectedVector4Data(source); TestOperation( source, expected, - (s, d) => ImageSharp.Rgba32.PixelOperations.ToVector4SimdAligned(s, d.Span, 64) + (s, d) => ImageSharp.PixelFormats.Rgba32.PixelOperations.ToVector4SimdAligned(s, d.Span, 64) ); } @@ -50,14 +50,14 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats int times = 200000; int count = 1024; - using (IBuffer source = Configuration.Default.MemoryManager.Allocate(count)) + using (IBuffer source = Configuration.Default.MemoryManager.Allocate(count)) using (IBuffer dest = Configuration.Default.MemoryManager.Allocate(count)) { this.Measure( times, () => { - PixelOperations.Instance.ToVector4(source.Span, dest.Span, count); + PixelOperations.Instance.ToVector4(source.Span, dest.Span, count); }); } } diff --git a/tests/ImageSharp.Tests/Primitives/DenseMatrixTests.cs b/tests/ImageSharp.Tests/Primitives/DenseMatrixTests.cs new file mode 100644 index 0000000000..7d161d35f7 --- /dev/null +++ b/tests/ImageSharp.Tests/Primitives/DenseMatrixTests.cs @@ -0,0 +1,108 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using SixLabors.ImageSharp.Primitives; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Primitives +{ + public class DenseMatrixTests + { + private static readonly float[,] FloydSteinbergMatrix = + { + { 0, 0, 7 }, + { 3, 5, 1 } + }; + + [Fact] + public void DenseMatrixThrowsOnNullInitializer() + { + Assert.Throws(() => + { + var dense = new DenseMatrix(null); + }); + } + + [Fact] + public void DenseMatrixThrowsOnEmptyZeroWidth() + { + Assert.Throws(() => + { + var dense = new DenseMatrix(0, 10); + }); + } + + [Fact] + public void DenseMatrixThrowsOnEmptyZeroHeight() + { + Assert.Throws(() => + { + var dense = new DenseMatrix(10, 0); + }); + } + + [Fact] + public void DenseMatrixThrowsOnEmptyInitializer() + { + Assert.Throws(() => + { + var dense = new DenseMatrix(new float[0, 0]); + }); + } + + [Fact] + public void DenseMatrixReturnsCorrectDimensions() + { + var dense = new DenseMatrix(FloydSteinbergMatrix); + Assert.True(dense.Columns == FloydSteinbergMatrix.GetLength(1)); + Assert.True(dense.Rows == FloydSteinbergMatrix.GetLength(0)); + Assert.Equal(3, dense.Columns); + Assert.Equal(2, dense.Rows); + } + + [Fact] + public void DenseMatrixGetReturnsCorrectResults() + { + DenseMatrix dense = FloydSteinbergMatrix; + + for (int row = 0; row < dense.Rows; row++) + { + for (int column = 0; column < dense.Columns; column++) + { + Assert.True(Math.Abs(dense[row, column] - FloydSteinbergMatrix[row, column]) < Constants.Epsilon); + } + } + } + + [Fact] + public void DenseMatrixGetSetReturnsCorrectResults() + { + var dense = new DenseMatrix(4, 4); + const int Val = 5; + + dense[3, 3] = Val; + + Assert.Equal(Val, dense[3, 3]); + } + + [Fact] + public void DenseMatrixCanFillAndClear() + { + var dense = new DenseMatrix(9); + dense.Fill(4); + + for (int i = 0; i < dense.Data.Length; i++) + { + Assert.Equal(4, dense.Data[i]); + } + + dense.Clear(); + + for (int i = 0; i < dense.Data.Length; i++) + { + Assert.Equal(0, dense.Data[i]); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Binarization/BinaryDitherTest.cs b/tests/ImageSharp.Tests/Processing/Binarization/BinaryDitherTest.cs index 003f998d88..a742171b19 100644 --- a/tests/ImageSharp.Tests/Processing/Binarization/BinaryDitherTest.cs +++ b/tests/ImageSharp.Tests/Processing/Binarization/BinaryDitherTest.cs @@ -1,13 +1,18 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Dithering; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; + using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Binarization { + using SixLabors.ImageSharp.Processing.Binarization; + using SixLabors.ImageSharp.Processing.Binarization.Processors; + using SixLabors.ImageSharp.Processing.Dithering; + using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion; + using SixLabors.ImageSharp.Processing.Dithering.Ordered; + public class BinaryDitherTest : BaseImageOperationsExtensionTest { private readonly IOrderedDither orderedDither; @@ -15,8 +20,8 @@ namespace SixLabors.ImageSharp.Tests.Processing.Binarization public BinaryDitherTest() { - this.orderedDither = KnownDitherers.BayerDither4x4; - this.errorDiffuser = KnownDiffusers.FloydSteinberg; + this.orderedDither = DitherMode.BayerDither4x4; + this.errorDiffuser = DiffuseMode.FloydSteinberg; } [Fact] diff --git a/tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs b/tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs index 488b3d18b1..6029b0d5fa 100644 --- a/tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs +++ b/tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs @@ -8,6 +8,9 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Binarization { + using SixLabors.ImageSharp.Processing.Binarization; + using SixLabors.ImageSharp.Processing.Binarization.Processors; + public class BinaryThresholdTest : BaseImageOperationsExtensionTest { diff --git a/tests/ImageSharp.Tests/Processing/Binarization/OrderedDitherFactoryTests.cs b/tests/ImageSharp.Tests/Processing/Binarization/OrderedDitherFactoryTests.cs index a0ddc2c7cc..89e48cfa3f 100644 --- a/tests/ImageSharp.Tests/Processing/Binarization/OrderedDitherFactoryTests.cs +++ b/tests/ImageSharp.Tests/Processing/Binarization/OrderedDitherFactoryTests.cs @@ -1,22 +1,23 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Dithering; -using SixLabors.ImageSharp.Memory; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Binarization { + using SixLabors.ImageSharp.Primitives; + using SixLabors.ImageSharp.Processing.Dithering.Ordered; + public class OrderedDitherFactoryTests { - private static readonly Fast2DArray Expected2x2Matrix = new Fast2DArray( + private static readonly DenseMatrix Expected2x2Matrix = new DenseMatrix( new uint[2, 2] { { 0, 2 }, { 3, 1 } }); - private static readonly Fast2DArray Expected3x3Matrix = new Fast2DArray( + private static readonly DenseMatrix Expected3x3Matrix = new DenseMatrix( new uint[3, 3] { { 0, 5, 2 }, @@ -24,7 +25,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Binarization { 3, 6, 1 } }); - private static readonly Fast2DArray Expected4x4Matrix = new Fast2DArray( + private static readonly DenseMatrix Expected4x4Matrix = new DenseMatrix( new uint[4, 4] { { 0, 8, 2, 10 }, @@ -33,7 +34,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Binarization { 15, 7, 13, 5 } }); - private static readonly Fast2DArray Expected8x8Matrix = new Fast2DArray( + private static readonly DenseMatrix Expected8x8Matrix = new DenseMatrix( new uint[8, 8] { { 0, 32, 8, 40, 2, 34, 10, 42 }, @@ -50,10 +51,10 @@ namespace SixLabors.ImageSharp.Tests.Processing.Binarization [Fact] public void OrderedDitherFactoryCreatesCorrect2x2Matrix() { - Fast2DArray actual = OrderedDitherFactory.CreateDitherMatrix(2); - for (int y = 0; y < actual.Height; y++) + DenseMatrix actual = OrderedDitherFactory.CreateDitherMatrix(2); + for (int y = 0; y < actual.Rows; y++) { - for (int x = 0; x < actual.Width; x++) + for (int x = 0; x < actual.Columns; x++) { Assert.Equal(Expected2x2Matrix[y, x], actual[y, x]); } @@ -63,10 +64,10 @@ namespace SixLabors.ImageSharp.Tests.Processing.Binarization [Fact] public void OrderedDitherFactoryCreatesCorrect3x3Matrix() { - Fast2DArray actual = OrderedDitherFactory.CreateDitherMatrix(3); - for (int y = 0; y < actual.Height; y++) + DenseMatrix actual = OrderedDitherFactory.CreateDitherMatrix(3); + for (int y = 0; y < actual.Rows; y++) { - for (int x = 0; x < actual.Width; x++) + for (int x = 0; x < actual.Columns; x++) { Assert.Equal(Expected3x3Matrix[y, x], actual[y, x]); } @@ -76,10 +77,10 @@ namespace SixLabors.ImageSharp.Tests.Processing.Binarization [Fact] public void OrderedDitherFactoryCreatesCorrect4x4Matrix() { - Fast2DArray actual = OrderedDitherFactory.CreateDitherMatrix(4); - for (int y = 0; y < actual.Height; y++) + DenseMatrix actual = OrderedDitherFactory.CreateDitherMatrix(4); + for (int y = 0; y < actual.Rows; y++) { - for (int x = 0; x < actual.Width; x++) + for (int x = 0; x < actual.Columns; x++) { Assert.Equal(Expected4x4Matrix[y, x], actual[y, x]); } @@ -89,10 +90,10 @@ namespace SixLabors.ImageSharp.Tests.Processing.Binarization [Fact] public void OrderedDitherFactoryCreatesCorrect8x8Matrix() { - Fast2DArray actual = OrderedDitherFactory.CreateDitherMatrix(8); - for (int y = 0; y < actual.Height; y++) + DenseMatrix actual = OrderedDitherFactory.CreateDitherMatrix(8); + for (int y = 0; y < actual.Rows; y++) { - for (int x = 0; x < actual.Width; x++) + for (int x = 0; x < actual.Columns; x++) { Assert.Equal(Expected8x8Matrix[y, x], actual[y, x]); } diff --git a/tests/ImageSharp.Tests/Processing/Convolution/BoxBlurTest.cs b/tests/ImageSharp.Tests/Processing/Convolution/BoxBlurTest.cs index cd0e8e5ab0..07c69a94c2 100644 --- a/tests/ImageSharp.Tests/Processing/Convolution/BoxBlurTest.cs +++ b/tests/ImageSharp.Tests/Processing/Convolution/BoxBlurTest.cs @@ -8,6 +8,9 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Convolution { + using SixLabors.ImageSharp.Processing.Convolution; + using SixLabors.ImageSharp.Processing.Convolution.Processors; + public class BoxBlurTest : BaseImageOperationsExtensionTest { [Fact] diff --git a/tests/ImageSharp.Tests/Processing/Convolution/DetectEdgesTest.cs b/tests/ImageSharp.Tests/Processing/Convolution/DetectEdgesTest.cs index b52938aac1..45a5b03135 100644 --- a/tests/ImageSharp.Tests/Processing/Convolution/DetectEdgesTest.cs +++ b/tests/ImageSharp.Tests/Processing/Convolution/DetectEdgesTest.cs @@ -11,6 +11,9 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Convolution { + using SixLabors.ImageSharp.Processing.Convolution; + using SixLabors.ImageSharp.Processing.Convolution.Processors; + public class DetectEdgesTest : BaseImageOperationsExtensionTest { @@ -34,21 +37,21 @@ namespace SixLabors.ImageSharp.Tests.Processing.Convolution // Assert.True(processor.Grayscale); } public static IEnumerable EdgeDetectionTheoryData => new[] { - new object[]{ new TestType>(), EdgeDetection.Kayyali }, - new object[]{ new TestType>(), EdgeDetection.Kirsch }, - new object[]{ new TestType>(), EdgeDetection.Lapacian3X3 }, - new object[]{ new TestType>(), EdgeDetection.Lapacian5X5 }, - new object[]{ new TestType>(), EdgeDetection.LaplacianOfGaussian }, - new object[]{ new TestType>(), EdgeDetection.Prewitt }, - new object[]{ new TestType>(), EdgeDetection.RobertsCross }, - new object[]{ new TestType>(), EdgeDetection.Robinson }, - new object[]{ new TestType>(), EdgeDetection.Scharr }, - new object[]{ new TestType>(), EdgeDetection.Sobel }, + new object[]{ new TestType>(), EdgeDetectionOperators.Kayyali }, + new object[]{ new TestType>(), EdgeDetectionOperators.Kirsch }, + new object[]{ new TestType>(), EdgeDetectionOperators.Laplacian3x3 }, + new object[]{ new TestType>(), EdgeDetectionOperators.Laplacian5x5 }, + new object[]{ new TestType>(), EdgeDetectionOperators.LaplacianOfGaussian }, + new object[]{ new TestType>(), EdgeDetectionOperators.Prewitt }, + new object[]{ new TestType>(), EdgeDetectionOperators.RobertsCross }, + new object[]{ new TestType>(), EdgeDetectionOperators.Robinson }, + new object[]{ new TestType>(), EdgeDetectionOperators.Scharr }, + new object[]{ new TestType>(), EdgeDetectionOperators.Sobel }, }; [Theory] [MemberData(nameof(EdgeDetectionTheoryData))] - public void DetectEdges_filter_SobelProcessorDefaultsSet(TestType type, EdgeDetection filter) + public void DetectEdges_filter_SobelProcessorDefaultsSet(TestType type, EdgeDetectionOperators filter) where TProcessor : IEdgeDetectorProcessor { this.operations.DetectEdges(filter); @@ -60,7 +63,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Convolution [Theory] [MemberData(nameof(EdgeDetectionTheoryData))] - public void DetectEdges_filter_grayscale_SobelProcessorDefaultsSet(TestType type, EdgeDetection filter) + public void DetectEdges_filter_grayscale_SobelProcessorDefaultsSet(TestType type, EdgeDetectionOperators filter) where TProcessor : IEdgeDetectorProcessor { bool grey = (int)filter % 2 == 0; diff --git a/tests/ImageSharp.Tests/Processing/Convolution/GaussianBlurTest.cs b/tests/ImageSharp.Tests/Processing/Convolution/GaussianBlurTest.cs index d0773a0bfe..5399a7ec83 100644 --- a/tests/ImageSharp.Tests/Processing/Convolution/GaussianBlurTest.cs +++ b/tests/ImageSharp.Tests/Processing/Convolution/GaussianBlurTest.cs @@ -8,6 +8,9 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Convolution { + using SixLabors.ImageSharp.Processing.Convolution; + using SixLabors.ImageSharp.Processing.Convolution.Processors; + public class GaussianBlurTest : BaseImageOperationsExtensionTest { [Fact] diff --git a/tests/ImageSharp.Tests/Processing/Convolution/GaussianSharpenTest.cs b/tests/ImageSharp.Tests/Processing/Convolution/GaussianSharpenTest.cs index c7c78a21a6..518c2960fb 100644 --- a/tests/ImageSharp.Tests/Processing/Convolution/GaussianSharpenTest.cs +++ b/tests/ImageSharp.Tests/Processing/Convolution/GaussianSharpenTest.cs @@ -8,6 +8,9 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Convolution { + using SixLabors.ImageSharp.Processing.Convolution; + using SixLabors.ImageSharp.Processing.Convolution.Processors; + public class GaussianSharpenTest : BaseImageOperationsExtensionTest { [Fact] diff --git a/tests/ImageSharp.Tests/Processing/Convolution/Processors/LaplacianKernelFactoryTests.cs b/tests/ImageSharp.Tests/Processing/Convolution/Processors/LaplacianKernelFactoryTests.cs new file mode 100644 index 0000000000..439632210f --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Convolution/Processors/LaplacianKernelFactoryTests.cs @@ -0,0 +1,68 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using SixLabors.ImageSharp.Primitives; +using SixLabors.ImageSharp.Processing.Convolution.Processors; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Processing.Convolution.Processors +{ + public class LaplacianKernelFactoryTests + { + private static readonly ApproximateFloatComparer ApproximateComparer = new ApproximateFloatComparer(0.0001F); + + private static readonly DenseMatrix Expected3x3Matrix = new DenseMatrix( + new float[,] + { + { -1, -1, -1 }, + { -1, 8, -1 }, + { -1, -1, -1 } + }); + + private static readonly DenseMatrix Expected5x5Matrix = new DenseMatrix( + new float[,] + { + { -1, -1, -1,-1, -1 }, + { -1, -1, -1,-1, -1 }, + { -1, -1, 24,-1, -1 }, + { -1, -1, -1,-1, -1 }, + { -1, -1, -1,-1, -1 } + }); + + [Fact] + public void LaplacianKernelFactoryOutOfRangeThrows() + { + Assert.Throws(() => + { + LaplacianKernelFactory.CreateKernel(2); + }); + } + + [Fact] + public void LaplacianKernelFactoryCreatesCorrect3x3Matrix() + { + DenseMatrix actual = LaplacianKernelFactory.CreateKernel(3); + for (int y = 0; y < actual.Rows; y++) + { + for (int x = 0; x < actual.Columns; x++) + { + Assert.Equal(Expected3x3Matrix[y, x], actual[y, x], ApproximateComparer); + } + } + } + + [Fact] + public void LaplacianKernelFactoryCreatesCorrect5x5Matrix() + { + DenseMatrix actual = LaplacianKernelFactory.CreateKernel(5); + for (int y = 0; y < actual.Rows; y++) + { + for (int x = 0; x < actual.Columns; x++) + { + Assert.Equal(Expected5x5Matrix[y, x], actual[y, x], ApproximateComparer); + } + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/DelegateTest.cs b/tests/ImageSharp.Tests/Processing/DelegateTest.cs index 518a28bea0..73d3c80230 100644 --- a/tests/ImageSharp.Tests/Processing/DelegateTest.cs +++ b/tests/ImageSharp.Tests/Processing/DelegateTest.cs @@ -8,6 +8,8 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing { + using SixLabors.ImageSharp.Processing.Processors; + public class DelegateTest : BaseImageOperationsExtensionTest { [Fact] diff --git a/tests/ImageSharp.Tests/Processing/Dithering/DitherTest.cs b/tests/ImageSharp.Tests/Processing/Dithering/DitherTest.cs index 03ae17848c..69aee9bc81 100644 --- a/tests/ImageSharp.Tests/Processing/Dithering/DitherTest.cs +++ b/tests/ImageSharp.Tests/Processing/Dithering/DitherTest.cs @@ -1,13 +1,17 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Dithering; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; + using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Binarization { + using SixLabors.ImageSharp.Processing.Dithering; + using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion; + using SixLabors.ImageSharp.Processing.Dithering.Ordered; + using SixLabors.ImageSharp.Processing.Dithering.Processors; + public class DitherTest : BaseImageOperationsExtensionTest { private readonly IOrderedDither orderedDither; @@ -21,8 +25,8 @@ namespace SixLabors.ImageSharp.Tests.Processing.Binarization public DitherTest() { - this.orderedDither = KnownDitherers.BayerDither4x4; - this.errorDiffuser = KnownDiffusers.FloydSteinberg; + this.orderedDither = DitherMode.BayerDither4x4; + this.errorDiffuser = DiffuseMode.FloydSteinberg; } [Fact] diff --git a/tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs b/tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs index a24b8a4d47..d7204d0cf4 100644 --- a/tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs +++ b/tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs @@ -2,12 +2,14 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; -using SixLabors.Primitives; + using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Effects { + using SixLabors.ImageSharp.Processing.Overlays; + using SixLabors.ImageSharp.Processing.Overlays.Processors; + public class BackgroundColorTest : BaseImageOperationsExtensionTest { [Fact] @@ -17,7 +19,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Effects var processor = this.Verify>(); Assert.Equal(GraphicsOptions.Default, processor.GraphicsOptions); - Assert.Equal(Rgba32.BlanchedAlmond, processor.Value); + Assert.Equal(Rgba32.BlanchedAlmond, processor.Color); } [Fact] @@ -27,7 +29,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Effects var processor = this.Verify>(this.rect); Assert.Equal(GraphicsOptions.Default, processor.GraphicsOptions); - Assert.Equal(Rgba32.BlanchedAlmond, processor.Value); + Assert.Equal(Rgba32.BlanchedAlmond, processor.Color); } [Fact] @@ -37,7 +39,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Effects var processor = this.Verify>(); Assert.Equal(this.options, processor.GraphicsOptions); - Assert.Equal(Rgba32.BlanchedAlmond, processor.Value); + Assert.Equal(Rgba32.BlanchedAlmond, processor.Color); } [Fact] @@ -47,7 +49,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Effects var processor = this.Verify>(this.rect); Assert.Equal(this.options, processor.GraphicsOptions); - Assert.Equal(Rgba32.BlanchedAlmond, processor.Value); + Assert.Equal(Rgba32.BlanchedAlmond, processor.Color); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Effects/OilPaintTest.cs b/tests/ImageSharp.Tests/Processing/Effects/OilPaintTest.cs index 36de67188f..f40cc250bb 100644 --- a/tests/ImageSharp.Tests/Processing/Effects/OilPaintTest.cs +++ b/tests/ImageSharp.Tests/Processing/Effects/OilPaintTest.cs @@ -8,6 +8,9 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Effects { + using SixLabors.ImageSharp.Processing.Effects; + using SixLabors.ImageSharp.Processing.Effects.Processors; + public class OilPaintTest : BaseImageOperationsExtensionTest { [Fact] diff --git a/tests/ImageSharp.Tests/Processing/Effects/PixelateTest.cs b/tests/ImageSharp.Tests/Processing/Effects/PixelateTest.cs index 8b50e14861..1cc69bcb68 100644 --- a/tests/ImageSharp.Tests/Processing/Effects/PixelateTest.cs +++ b/tests/ImageSharp.Tests/Processing/Effects/PixelateTest.cs @@ -8,6 +8,9 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Effects { + using SixLabors.ImageSharp.Processing.Effects; + using SixLabors.ImageSharp.Processing.Effects.Processors; + public class PixelateTest : BaseImageOperationsExtensionTest { [Fact] diff --git a/tests/ImageSharp.Tests/Processing/Filters/BlackWhiteTest.cs b/tests/ImageSharp.Tests/Processing/Filters/BlackWhiteTest.cs index 4ade9fe64b..db10c16b11 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/BlackWhiteTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/BlackWhiteTest.cs @@ -1,11 +1,15 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Filters { + using SixLabors.ImageSharp.Processing.Filters; + using SixLabors.ImageSharp.Processing.Filters.Processors; + public class BlackWhiteTest : BaseImageOperationsExtensionTest { [Fact] diff --git a/tests/ImageSharp.Tests/Processing/Filters/BrightnessTest.cs b/tests/ImageSharp.Tests/Processing/Filters/BrightnessTest.cs index 05605767fb..dc3281a638 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/BrightnessTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/BrightnessTest.cs @@ -8,6 +8,9 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Effects { + using SixLabors.ImageSharp.Processing.Filters; + using SixLabors.ImageSharp.Processing.Filters.Processors; + public class BrightnessTest : BaseImageOperationsExtensionTest { [Fact] diff --git a/tests/ImageSharp.Tests/Processing/Filters/ColorBlindnessTest.cs b/tests/ImageSharp.Tests/Processing/Filters/ColorBlindnessTest.cs index 2dc695f560..29d18897fb 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/ColorBlindnessTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/ColorBlindnessTest.cs @@ -2,15 +2,18 @@ // Licensed under the Apache License, Version 2.0. using System.Collections.Generic; + using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Processors; using SixLabors.ImageSharp.Tests.TestUtilities; -using SixLabors.Primitives; + using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Filters { + using SixLabors.ImageSharp.Processing.Filters; + using SixLabors.ImageSharp.Processing.Filters.Processors; + using SixLabors.ImageSharp.Processing.Processors; + public class ColorBlindnessTest : BaseImageOperationsExtensionTest { public static IEnumerable TheoryData = new[] { diff --git a/tests/ImageSharp.Tests/Processing/Filters/ContrastTest.cs b/tests/ImageSharp.Tests/Processing/Filters/ContrastTest.cs index 4aec24dad0..2f9a8331de 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/ContrastTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/ContrastTest.cs @@ -1,11 +1,15 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Effects { + using SixLabors.ImageSharp.Processing.Filters; + using SixLabors.ImageSharp.Processing.Filters.Processors; + public class ContrastTest : BaseImageOperationsExtensionTest { [Fact] diff --git a/tests/ImageSharp.Tests/Processing/Filters/FilterTest.cs b/tests/ImageSharp.Tests/Processing/Filters/FilterTest.cs index d1e9c0ba0a..77325b24cc 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/FilterTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/FilterTest.cs @@ -1,12 +1,16 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Filters { + using SixLabors.ImageSharp.Processing.Filters; + using SixLabors.ImageSharp.Processing.Filters.Processors; + public class FilterTest : BaseImageOperationsExtensionTest { [Fact] diff --git a/tests/ImageSharp.Tests/Processing/Filters/GrayscaleTest.cs b/tests/ImageSharp.Tests/Processing/Filters/GrayscaleTest.cs index 80c377eb1d..ad12d07a85 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/GrayscaleTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/GrayscaleTest.cs @@ -1,17 +1,19 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System.Collections; using System.Collections.Generic; + using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Processors; using SixLabors.ImageSharp.Tests.TestUtilities; -using SixLabors.Primitives; + using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Filters { + using SixLabors.ImageSharp.Processing.Filters; + using SixLabors.ImageSharp.Processing.Filters.Processors; + using SixLabors.ImageSharp.Processing.Processors; + public class GrayscaleTest : BaseImageOperationsExtensionTest { public static IEnumerable ModeTheoryData = new[] { diff --git a/tests/ImageSharp.Tests/Processing/Filters/HueTest.cs b/tests/ImageSharp.Tests/Processing/Filters/HueTest.cs index bf03ee4f81..e9f79ff1d4 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/HueTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/HueTest.cs @@ -8,6 +8,9 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Filters { + using SixLabors.ImageSharp.Processing.Filters; + using SixLabors.ImageSharp.Processing.Filters.Processors; + public class HueTest : BaseImageOperationsExtensionTest { [Fact] diff --git a/tests/ImageSharp.Tests/Processing/Filters/InvertTest.cs b/tests/ImageSharp.Tests/Processing/Filters/InvertTest.cs index ad74b3c909..24d33e9f7d 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/InvertTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/InvertTest.cs @@ -8,6 +8,9 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Effects { + using SixLabors.ImageSharp.Processing.Filters; + using SixLabors.ImageSharp.Processing.Filters.Processors; + public class InvertTest : BaseImageOperationsExtensionTest { [Fact] diff --git a/tests/ImageSharp.Tests/Processing/Filters/KodachromeTest.cs b/tests/ImageSharp.Tests/Processing/Filters/KodachromeTest.cs index b3731d43c1..d776a9c8a7 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/KodachromeTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/KodachromeTest.cs @@ -8,6 +8,9 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Filters { + using SixLabors.ImageSharp.Processing.Filters; + using SixLabors.ImageSharp.Processing.Filters.Processors; + public class KodachromeTest : BaseImageOperationsExtensionTest { [Fact] diff --git a/tests/ImageSharp.Tests/Processing/Filters/LomographTest.cs b/tests/ImageSharp.Tests/Processing/Filters/LomographTest.cs index 32107cb716..5bd4394ab2 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/LomographTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/LomographTest.cs @@ -9,6 +9,9 @@ using Xunit; namespace SixLabors.ImageSharp.Tests { + using SixLabors.ImageSharp.Processing.Filters; + using SixLabors.ImageSharp.Processing.Filters.Processors; + public class LomographTest : BaseImageOperationsExtensionTest { [Fact] diff --git a/tests/ImageSharp.Tests/Processing/Filters/OpacityTest.cs b/tests/ImageSharp.Tests/Processing/Filters/OpacityTest.cs index 4108cbddac..f40f927188 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/OpacityTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/OpacityTest.cs @@ -1,11 +1,15 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Effects { + using SixLabors.ImageSharp.Processing.Filters; + using SixLabors.ImageSharp.Processing.Filters.Processors; + public class OpacityTest : BaseImageOperationsExtensionTest { [Fact] diff --git a/tests/ImageSharp.Tests/Processing/Filters/PolaroidTest.cs b/tests/ImageSharp.Tests/Processing/Filters/PolaroidTest.cs index 5661851a56..5e43245af6 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/PolaroidTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/PolaroidTest.cs @@ -8,6 +8,9 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Filters { + using SixLabors.ImageSharp.Processing.Filters; + using SixLabors.ImageSharp.Processing.Filters.Processors; + public class PolaroidTest : BaseImageOperationsExtensionTest { [Fact] diff --git a/tests/ImageSharp.Tests/Processing/Filters/SaturateTest.cs b/tests/ImageSharp.Tests/Processing/Filters/SaturateTest.cs index e3b9e3d3b2..72ab0fe70f 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/SaturateTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/SaturateTest.cs @@ -1,11 +1,15 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Filters { + using SixLabors.ImageSharp.Processing.Filters; + using SixLabors.ImageSharp.Processing.Filters.Processors; + public class SaturateTest : BaseImageOperationsExtensionTest { diff --git a/tests/ImageSharp.Tests/Processing/Filters/SepiaTest.cs b/tests/ImageSharp.Tests/Processing/Filters/SepiaTest.cs index 4983313882..b8a77c9f05 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/SepiaTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/SepiaTest.cs @@ -8,6 +8,9 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Filters { + using SixLabors.ImageSharp.Processing.Filters; + using SixLabors.ImageSharp.Processing.Filters.Processors; + public class SepiaTest : BaseImageOperationsExtensionTest { [Fact] diff --git a/tests/ImageSharp.Tests/Processing/Overlays/GlowTest.cs b/tests/ImageSharp.Tests/Processing/Overlays/GlowTest.cs index 9e7a046507..4165ea24ef 100644 --- a/tests/ImageSharp.Tests/Processing/Overlays/GlowTest.cs +++ b/tests/ImageSharp.Tests/Processing/Overlays/GlowTest.cs @@ -2,8 +2,11 @@ // Licensed under the Apache License, Version 2.0. using System; + using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Primitives; +using SixLabors.ImageSharp.Processing.Overlays; +using SixLabors.ImageSharp.Processing.Overlays.Processors; using SixLabors.Primitives; using Xunit; diff --git a/tests/ImageSharp.Tests/Processing/Overlays/VignetteTest.cs b/tests/ImageSharp.Tests/Processing/Overlays/VignetteTest.cs index e082e42cd7..bd42cf14e0 100644 --- a/tests/ImageSharp.Tests/Processing/Overlays/VignetteTest.cs +++ b/tests/ImageSharp.Tests/Processing/Overlays/VignetteTest.cs @@ -1,10 +1,10 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; -using SixLabors.ImageSharp.Tests.TestUtilities; +using SixLabors.ImageSharp.Primitives; +using SixLabors.ImageSharp.Processing.Overlays; +using SixLabors.ImageSharp.Processing.Overlays.Processors; using SixLabors.Primitives; using Xunit; diff --git a/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryDitherTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryDitherTests.cs index aec201239d..2937573395 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryDitherTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryDitherTests.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Dithering; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; @@ -11,6 +10,12 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization { + using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Binarization; + using SixLabors.ImageSharp.Processing.Dithering; + using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion; + using SixLabors.ImageSharp.Processing.Dithering.Ordered; + public class BinaryDitherTests : FileTestBase { public static readonly string[] CommonTestImages = @@ -18,35 +23,35 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization TestImages.Png.CalliphoraPartial, TestImages.Png.Bike }; - public static readonly TheoryData Ditherers = new TheoryData + public static readonly TheoryData OrderedDitherers = new TheoryData { - { "Bayer8x8", KnownDitherers.BayerDither8x8 }, - { "Bayer4x4", KnownDitherers.BayerDither4x4 }, - { "Ordered3x3", KnownDitherers.OrderedDither3x3 }, - { "Bayer2x2", KnownDitherers.BayerDither2x2 } + { "Bayer8x8", DitherMode.BayerDither8x8 }, + { "Bayer4x4", DitherMode.BayerDither4x4 }, + { "Ordered3x3", DitherMode.OrderedDither3x3 }, + { "Bayer2x2", DitherMode.BayerDither2x2 } }; public static readonly TheoryData ErrorDiffusers = new TheoryData { - { "Atkinson", KnownDiffusers.Atkinson }, - { "Burks", KnownDiffusers.Burks }, - { "FloydSteinberg", KnownDiffusers.FloydSteinberg }, - { "JarvisJudiceNinke", KnownDiffusers.JarvisJudiceNinke }, - { "Sierra2", KnownDiffusers.Sierra2 }, - { "Sierra3", KnownDiffusers.Sierra3 }, - { "SierraLite", KnownDiffusers.SierraLite }, - { "StevensonArce", KnownDiffusers.StevensonArce }, - { "Stucki", KnownDiffusers.Stucki }, + { "Atkinson", DiffuseMode.Atkinson }, + { "Burks", DiffuseMode.Burks }, + { "FloydSteinberg", DiffuseMode.FloydSteinberg }, + { "JarvisJudiceNinke", DiffuseMode.JarvisJudiceNinke }, + { "Sierra2", DiffuseMode.Sierra2 }, + { "Sierra3", DiffuseMode.Sierra3 }, + { "SierraLite", DiffuseMode.SierraLite }, + { "StevensonArce", DiffuseMode.StevensonArce }, + { "Stucki", DiffuseMode.Stucki }, }; - private static IOrderedDither DefaultDitherer => KnownDitherers.BayerDither4x4; + private static IOrderedDither DefaultDitherer => DitherMode.BayerDither4x4; - private static IErrorDiffuser DefaultErrorDiffuser => KnownDiffusers.Atkinson; + private static IErrorDiffuser DefaultErrorDiffuser => DiffuseMode.Atkinson; [Theory] - [WithFileCollection(nameof(CommonTestImages), nameof(Ditherers), DefaultPixelType)] - [WithTestPatternImages(nameof(Ditherers), 100, 100, DefaultPixelType)] + [WithFileCollection(nameof(CommonTestImages), nameof(OrderedDitherers), DefaultPixelType)] + [WithTestPatternImages(nameof(OrderedDitherers), 100, 100, DefaultPixelType)] public void BinaryDitherFilter_WorksWithAllDitherers(TestImageProvider provider, string name, IOrderedDither ditherer) where TPixel : struct, IPixel { diff --git a/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs index 3daeecfc75..b1092782cc 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs @@ -9,6 +9,9 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization { + using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Binarization; + public class BinaryThresholdTest : FileTestBase { public static readonly TheoryData BinaryThresholdValues diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/BoxBlurTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/BoxBlurTest.cs index 94af7aa37e..b49fbf435e 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Convolution/BoxBlurTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/BoxBlurTest.cs @@ -9,6 +9,9 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution { + using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Convolution; + public class BoxBlurTest : FileTestBase { public static readonly TheoryData BoxBlurValues diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs index 323842556e..a3687f7b5f 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs @@ -10,28 +10,30 @@ using Xunit; // ReSharper disable InconsistentNaming namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution { + using SixLabors.ImageSharp.Processing.Convolution; + public class DetectEdgesTest : FileTestBase { public static readonly string[] CommonTestImages = { TestImages.Png.Bike }; - public static readonly TheoryData DetectEdgesFilters = new TheoryData + public static readonly TheoryData DetectEdgesFilters = new TheoryData { - EdgeDetection.Kayyali, - EdgeDetection.Kirsch, - EdgeDetection.Lapacian3X3, - EdgeDetection.Lapacian5X5, - EdgeDetection.LaplacianOfGaussian, - EdgeDetection.Prewitt, - EdgeDetection.RobertsCross, - EdgeDetection.Robinson, - EdgeDetection.Scharr, - EdgeDetection.Sobel + EdgeDetectionOperators.Kayyali, + EdgeDetectionOperators.Kirsch, + EdgeDetectionOperators.Laplacian3x3, + EdgeDetectionOperators.Laplacian5x5, + EdgeDetectionOperators.LaplacianOfGaussian, + EdgeDetectionOperators.Prewitt, + EdgeDetectionOperators.RobertsCross, + EdgeDetectionOperators.Robinson, + EdgeDetectionOperators.Scharr, + EdgeDetectionOperators.Sobel }; [Theory] [WithTestPatternImages(nameof(DetectEdgesFilters), 100, 100, DefaultPixelType)] [WithFileCollection(nameof(CommonTestImages), nameof(DetectEdgesFilters), DefaultPixelType)] - public void DetectEdges_WorksWithAllFilters(TestImageProvider provider, EdgeDetection detector) + public void DetectEdges_WorksWithAllFilters(TestImageProvider provider, EdgeDetectionOperators detector) where TPixel : struct, IPixel { using (Image image = provider.GetImage()) diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs index 89e9a13b5c..69a635e9d7 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs @@ -9,6 +9,9 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution { + using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Convolution; + public class GaussianBlurTest : FileTestBase { public static readonly TheoryData GaussianBlurValues = new TheoryData { 3, 5 }; diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs index 4775444a5a..468aa277c6 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs @@ -9,6 +9,9 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution { + using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Convolution; + public class GaussianSharpenTest : FileTestBase { public static readonly TheoryData GaussianSharpenValues diff --git a/tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs index 58c63d48c7..3bb3aedfcf 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs @@ -1,16 +1,20 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Dithering; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; - +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Dithering; +using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion; +using SixLabors.ImageSharp.Processing.Dithering.Ordered; using SixLabors.Primitives; using Xunit; // ReSharper disable InconsistentNaming namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization { + + public class DitherTests : FileTestBase { public static readonly string[] CommonTestImages = @@ -18,35 +22,35 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization TestImages.Png.CalliphoraPartial, TestImages.Png.Bike }; - public static readonly TheoryData Ditherers = new TheoryData + public static readonly TheoryData OrderedDitherers = new TheoryData { - { "Bayer8x8", KnownDitherers.BayerDither8x8 }, - { "Bayer4x4", KnownDitherers.BayerDither4x4 }, - { "Ordered3x3", KnownDitherers.OrderedDither3x3 }, - { "Bayer2x2", KnownDitherers.BayerDither2x2 } + { "Bayer8x8", DitherMode.BayerDither8x8 }, + { "Bayer4x4", DitherMode.BayerDither4x4 }, + { "Ordered3x3", DitherMode.OrderedDither3x3 }, + { "Bayer2x2", DitherMode.BayerDither2x2 } }; public static readonly TheoryData ErrorDiffusers = new TheoryData { - { "Atkinson", KnownDiffusers.Atkinson }, - { "Burks", KnownDiffusers.Burks }, - { "FloydSteinberg", KnownDiffusers.FloydSteinberg }, - { "JarvisJudiceNinke", KnownDiffusers.JarvisJudiceNinke }, - { "Sierra2", KnownDiffusers.Sierra2 }, - { "Sierra3", KnownDiffusers.Sierra3 }, - { "SierraLite", KnownDiffusers.SierraLite }, - { "StevensonArce", KnownDiffusers.StevensonArce }, - { "Stucki", KnownDiffusers.Stucki }, + { "Atkinson", DiffuseMode.Atkinson }, + { "Burks", DiffuseMode.Burks }, + { "FloydSteinberg", DiffuseMode.FloydSteinberg }, + { "JarvisJudiceNinke", DiffuseMode.JarvisJudiceNinke }, + { "Sierra2", DiffuseMode.Sierra2 }, + { "Sierra3", DiffuseMode.Sierra3 }, + { "SierraLite", DiffuseMode.SierraLite }, + { "StevensonArce", DiffuseMode.StevensonArce }, + { "Stucki", DiffuseMode.Stucki }, }; - private static IOrderedDither DefaultDitherer => KnownDitherers.BayerDither4x4; + private static IOrderedDither DefaultDitherer => DitherMode.BayerDither4x4; - private static IErrorDiffuser DefaultErrorDiffuser => KnownDiffusers.Atkinson; + private static IErrorDiffuser DefaultErrorDiffuser => DiffuseMode.Atkinson; [Theory] - [WithFileCollection(nameof(CommonTestImages), nameof(Ditherers), DefaultPixelType)] - [WithTestPatternImages(nameof(Ditherers), 100, 100, DefaultPixelType)] + [WithFileCollection(nameof(CommonTestImages), nameof(OrderedDitherers), DefaultPixelType)] + [WithTestPatternImages(nameof(OrderedDitherers), 100, 100, DefaultPixelType)] public void DitherFilter_WorksWithAllDitherers(TestImageProvider provider, string name, IOrderedDither ditherer) where TPixel : struct, IPixel { diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs index 2dd44b3a76..1e234e81ea 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs @@ -9,6 +9,9 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects { + using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Overlays; + public class BackgroundColorTest : FileTestBase { [Theory] diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs index a9127f61dc..715e997bf1 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs @@ -9,6 +9,9 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects { + using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Effects; + public class OilPaintTest : FileTestBase { public static readonly TheoryData OilPaintValues = new TheoryData diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs index b3f1ee3a28..84831e4159 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs @@ -9,6 +9,9 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects { + using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Effects; + public class PixelateTest : FileTestBase { public static readonly TheoryData PixelateValues diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/BlackWhiteTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/BlackWhiteTest.cs index e373230a73..ccf9152f0e 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/BlackWhiteTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Filters/BlackWhiteTest.cs @@ -7,6 +7,8 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters { + using SixLabors.ImageSharp.Processing.Filters; + [GroupOutput("Filters")] public class BlackWhiteTest { diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/BrightnessTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/BrightnessTest.cs index 783e55d832..14f5fa0808 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/BrightnessTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Filters/BrightnessTest.cs @@ -7,6 +7,8 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects { + using SixLabors.ImageSharp.Processing.Filters; + [GroupOutput("Filters")] public class BrightnessTest { diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/ColorBlindnessTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/ColorBlindnessTest.cs index c0df24d291..b0dcbd726b 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/ColorBlindnessTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Filters/ColorBlindnessTest.cs @@ -8,6 +8,8 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters { + using SixLabors.ImageSharp.Processing.Filters; + [GroupOutput("Filters")] public class ColorBlindnessTest { diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/ContrastTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/ContrastTest.cs index b532649b3d..c6afc5e11b 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/ContrastTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Filters/ContrastTest.cs @@ -7,6 +7,8 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects { + using SixLabors.ImageSharp.Processing.Filters; + [GroupOutput("Filters")] public class ContrastTest { diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/FilterTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/FilterTest.cs index 515b970aee..077073b4c7 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/FilterTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Filters/FilterTest.cs @@ -11,6 +11,8 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters { + using SixLabors.ImageSharp.Processing.Filters; + [GroupOutput("Filters")] public class FilterTest { diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/GrayscaleTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/GrayscaleTest.cs index f61c529a38..192034fbb6 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/GrayscaleTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Filters/GrayscaleTest.cs @@ -9,6 +9,8 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters { + using SixLabors.ImageSharp.Processing.Filters; + [GroupOutput("Filters")] public class GrayscaleTest { diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/HueTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/HueTest.cs index fe9f9d5db2..6e3fd5feff 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/HueTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Filters/HueTest.cs @@ -7,6 +7,8 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters { + using SixLabors.ImageSharp.Processing.Filters; + [GroupOutput("Filters")] public class HueTest { diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/InvertTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/InvertTest.cs index 452397c5eb..de105437ba 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/InvertTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Filters/InvertTest.cs @@ -7,6 +7,8 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects { + using SixLabors.ImageSharp.Processing.Filters; + [GroupOutput("Filters")] public class InvertTest { diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/KodachromeTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/KodachromeTest.cs index a5165250b7..2265e0b0b0 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/KodachromeTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Filters/KodachromeTest.cs @@ -7,6 +7,8 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters { + using SixLabors.ImageSharp.Processing.Filters; + [GroupOutput("Filters")] public class KodachromeTest { diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/LomographTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/LomographTest.cs index 09c8becec3..92c5b788cf 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/LomographTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Filters/LomographTest.cs @@ -7,6 +7,8 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters { + using SixLabors.ImageSharp.Processing.Filters; + [GroupOutput("Filters")] public class LomographTest { diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/OpacityTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/OpacityTest.cs index 2cba4fb8ed..c76bf3b1de 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/OpacityTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Filters/OpacityTest.cs @@ -7,6 +7,8 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects { + using SixLabors.ImageSharp.Processing.Filters; + [GroupOutput("Filters")] public class OpacityTest { diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/PolaroidTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/PolaroidTest.cs index 4e0347d2a4..19fcc67885 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/PolaroidTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Filters/PolaroidTest.cs @@ -7,6 +7,8 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters { + using SixLabors.ImageSharp.Processing.Filters; + [GroupOutput("Filters")] public class PolaroidTest { diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/SaturateTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/SaturateTest.cs index 9b963b94a4..18d77660e4 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/SaturateTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Filters/SaturateTest.cs @@ -7,6 +7,8 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters { + using SixLabors.ImageSharp.Processing.Filters; + [GroupOutput("Filters")] public class SaturateTest { diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/SepiaTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/SepiaTest.cs index 2a63e992d7..50bf0e3a1b 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/SepiaTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Filters/SepiaTest.cs @@ -7,6 +7,8 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters { + using SixLabors.ImageSharp.Processing.Filters; + [GroupOutput("Filters")] public class SepiaTest { diff --git a/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs index 5693b6d755..5c610fb316 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs @@ -9,6 +9,9 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Overlays { + using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Overlays; + public class GlowTest : FileTestBase { [Theory] diff --git a/tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs index 0d9c3e89b3..1c69b531c7 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs @@ -9,6 +9,9 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Overlays { + using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Overlays; + public class VignetteTest : FileTestBase { [Theory] diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/AutoOrientTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/AutoOrientTests.cs index 161ac15e33..fb1a7f0a38 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/AutoOrientTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/AutoOrientTests.cs @@ -9,6 +9,8 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms { + using SixLabors.ImageSharp.Processing.Transforms; + public class AutoOrientTests : FileTestBase { public static readonly string[] FlipFiles = { TestImages.Bmp.F }; diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/CropTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/CropTest.cs index aa18feac2d..e9fd50b7fa 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/CropTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/CropTest.cs @@ -6,6 +6,9 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms { + using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Transforms; + public class CropTest : FileTestBase { [Theory] diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/EntropyCropTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/EntropyCropTest.cs index 57341560e3..da3ba6be69 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/EntropyCropTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/EntropyCropTest.cs @@ -6,6 +6,9 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms { + using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Transforms; + public class EntropyCropTest : FileTestBase { public static readonly TheoryData EntropyCropValues diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs index 9ca3994986..7a4743e449 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs @@ -7,6 +7,8 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms { + using SixLabors.ImageSharp.Processing.Transforms; + public class FlipTests : FileTestBase { public static readonly string[] FlipFiles = { TestImages.Bmp.F }; diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/PadTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/PadTest.cs index b5f26b4883..3294ecc733 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/PadTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/PadTest.cs @@ -6,6 +6,9 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms { + using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Transforms; + public class PadTest : FileTestBase { [Theory] diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeProfilingBenchmarks.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeProfilingBenchmarks.cs index 2e1b43c388..bbb0b1db96 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeProfilingBenchmarks.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeProfilingBenchmarks.cs @@ -4,6 +4,8 @@ using System; using System.IO; using System.Text; + +using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors; using SixLabors.Primitives; @@ -12,6 +14,9 @@ using Xunit.Abstractions; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms { + using SixLabors.ImageSharp.Processing.Transforms; + using SixLabors.ImageSharp.Processing.Transforms.Processors; + public class ResizeProfilingBenchmarks : MeasureFixture { public ResizeProfilingBenchmarks(ITestOutputHelper output) @@ -40,7 +45,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms public void PrintWeightsData() { var size = new Size(500, 500); - var proc = new ResizeProcessor(KnownResamplers.Bicubic, 200, 200, size); + var proc = new ResizeProcessor(ResampleMode.Bicubic, 200, 200, size); WeightsBuffer weights = proc.PrecomputeWeights(Configuration.Default.MemoryManager, proc.Width, size.Width); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs index 8370a802cd..46e7b119e2 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs @@ -2,17 +2,17 @@ // Licensed under the Apache License, Version 2.0. using System; - -using SixLabors.ImageSharp.Helpers; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; - +using SixLabors.ImageSharp.Processing.Transforms.Resamplers; using SixLabors.Primitives; using Xunit; // ReSharper disable InconsistentNaming namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms { + using SixLabors.ImageSharp.Processing.Transforms; + public class ResizeTests : FileTestBase { public static readonly string[] CommonTestImages = { TestImages.Png.CalliphoraPartial }; @@ -20,20 +20,20 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms public static readonly TheoryData AllReSamplers = new TheoryData { - { "Bicubic", KnownResamplers.Bicubic }, - { "Triangle", KnownResamplers.Triangle}, - { "NearestNeighbor", KnownResamplers.NearestNeighbor }, - { "Box", KnownResamplers.Box }, + { "Bicubic", ResampleMode.Bicubic }, + { "Triangle", ResampleMode.Triangle}, + { "NearestNeighbor", ResampleMode.NearestNeighbor }, + { "Box", ResampleMode.Box }, // { "Lanczos2", KnownResamplers.Lanczos2 }, TODO: Add expected file - { "Lanczos3", KnownResamplers.Lanczos3 }, - { "Lanczos5", KnownResamplers.Lanczos5 }, - { "MitchellNetravali", KnownResamplers.MitchellNetravali }, - { "Lanczos8", KnownResamplers.Lanczos8 }, - { "Hermite", KnownResamplers.Hermite }, - { "Spline", KnownResamplers.Spline }, - { "Robidoux", KnownResamplers.Robidoux }, - { "RobidouxSharp", KnownResamplers.RobidouxSharp }, - { "Welch", KnownResamplers.Welch } + { "Lanczos3", ResampleMode.Lanczos3 }, + { "Lanczos5", ResampleMode.Lanczos5 }, + { "MitchellNetravali", ResampleMode.MitchellNetravali }, + { "Lanczos8", ResampleMode.Lanczos8 }, + { "Hermite", ResampleMode.Hermite }, + { "Spline", ResampleMode.Spline }, + { "Robidoux", ResampleMode.Robidoux }, + { "RobidouxSharp", ResampleMode.RobidouxSharp }, + { "Welch", ResampleMode.Welch } }; [Theory] @@ -102,7 +102,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms { using (Image image = provider.GetImage()) { - image.Mutate(x => x.Resize(image.Width / 2, image.Height / 2, KnownResamplers.NearestNeighbor)); + image.Mutate(x => x.Resize(image.Width / 2, image.Height / 2, ResampleMode.NearestNeighbor)); // Comparer fights decoder with gif-s. Could not use CompareToReferenceOutput here :( image.DebugSave(provider, extension: Extensions.Gif); @@ -119,7 +119,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms var sourceRectangle = new Rectangle(image.Width / 8, image.Height / 8, image.Width / 4, image.Height / 4); var destRectangle = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2); - image.Mutate(x => x.Resize(image.Width, image.Height, KnownResamplers.Bicubic, sourceRectangle, destRectangle, false)); + image.Mutate(x => x.Resize(image.Width, image.Height, ResampleMode.Bicubic, sourceRectangle, destRectangle, false)); image.DebugSave(provider); image.CompareToReferenceOutput(provider); @@ -300,7 +300,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms [InlineData(2, 0)] public static void BicubicWindowOscillatesCorrectly(float x, float expected) { - var sampler = KnownResamplers.Bicubic; + var sampler = ResampleMode.Bicubic; float result = sampler.GetValue(x); Assert.Equal(result, expected); @@ -314,7 +314,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms [InlineData(2, 0)] public static void TriangleWindowOscillatesCorrectly(float x, float expected) { - var sampler = KnownResamplers.Triangle; + var sampler = ResampleMode.Triangle; float result = sampler.GetValue(x); Assert.Equal(result, expected); @@ -328,7 +328,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms [InlineData(2, 0)] public static void Lanczos3WindowOscillatesCorrectly(float x, float expected) { - var sampler = KnownResamplers.Lanczos3; + var sampler = ResampleMode.Lanczos3; float result = sampler.GetValue(x); Assert.Equal(result, expected); @@ -342,7 +342,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms [InlineData(4, 0)] public static void Lanczos5WindowOscillatesCorrectly(float x, float expected) { - var sampler = KnownResamplers.Lanczos5; + var sampler = ResampleMode.Lanczos5; float result = sampler.GetValue(x); Assert.Equal(result, expected); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateFlipTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateFlipTests.cs index e7415e1619..f15ed3cc7e 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateFlipTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateFlipTests.cs @@ -7,6 +7,8 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms { + using SixLabors.ImageSharp.Processing.Transforms; + public class RotateFlipTests : FileTestBase { public static readonly string[] FlipFiles = { TestImages.Bmp.F }; diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateTests.cs index b5220ea948..54e2a4a185 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateTests.cs @@ -11,6 +11,8 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms using System; using System.Reflection; + using SixLabors.ImageSharp.Processing.Transforms; + public class RotateTests : FileTestBase { public static readonly TheoryData RotateAngles diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/SkewTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/SkewTest.cs index 17bf3def26..174aadf602 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/SkewTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/SkewTest.cs @@ -11,6 +11,8 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms using System.Reflection; using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Transforms; + using SixLabors.ImageSharp.Processing.Transforms.Resamplers; public class SkewTest : FileTestBase { @@ -24,21 +26,21 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms public static readonly List ResamplerNames = new List { - nameof(KnownResamplers.Bicubic), - nameof(KnownResamplers.Box), - nameof(KnownResamplers.CatmullRom), - nameof(KnownResamplers.Hermite), - nameof(KnownResamplers.Lanczos2), - nameof(KnownResamplers.Lanczos3), - nameof(KnownResamplers.Lanczos5), - nameof(KnownResamplers.Lanczos8), - nameof(KnownResamplers.MitchellNetravali), - nameof(KnownResamplers.NearestNeighbor), - nameof(KnownResamplers.Robidoux), - nameof(KnownResamplers.RobidouxSharp), - nameof(KnownResamplers.Spline), - nameof(KnownResamplers.Triangle), - nameof(KnownResamplers.Welch), + nameof(ResampleMode.Bicubic), + nameof(ResampleMode.Box), + nameof(ResampleMode.CatmullRom), + nameof(ResampleMode.Hermite), + nameof(ResampleMode.Lanczos2), + nameof(ResampleMode.Lanczos3), + nameof(ResampleMode.Lanczos5), + nameof(ResampleMode.Lanczos8), + nameof(ResampleMode.MitchellNetravali), + nameof(ResampleMode.NearestNeighbor), + nameof(ResampleMode.Robidoux), + nameof(ResampleMode.RobidouxSharp), + nameof(ResampleMode.Spline), + nameof(ResampleMode.Triangle), + nameof(ResampleMode.Welch), }; [Theory] @@ -71,7 +73,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms private static IResampler GetResampler(string name) { - PropertyInfo property = typeof(KnownResamplers).GetTypeInfo().GetProperty(name); + PropertyInfo property = typeof(ResampleMode).GetTypeInfo().GetProperty(name); if (property == null) { diff --git a/tests/ImageSharp.Tests/Processing/Transforms/AffineTransformTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/AffineTransformTests.cs index ace6cb70d6..02144e0735 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/AffineTransformTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/AffineTransformTests.cs @@ -3,14 +3,16 @@ using System.Numerics; using System.Reflection; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Transforms.Resamplers; using SixLabors.Primitives; using Xunit; using Xunit.Abstractions; -using SixLabors.ImageSharp.Helpers; // ReSharper disable InconsistentNaming namespace SixLabors.ImageSharp.Tests.Processing.Transforms { + using SixLabors.ImageSharp.Processing.Transforms; + public class AffineTransformTests { private readonly ITestOutputHelper Output; @@ -36,30 +38,30 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms public static readonly TheoryData ResamplerNames = new TheoryData { - nameof(KnownResamplers.Bicubic), - nameof(KnownResamplers.Box), - nameof(KnownResamplers.CatmullRom), - nameof(KnownResamplers.Hermite), - nameof(KnownResamplers.Lanczos2), - nameof(KnownResamplers.Lanczos3), - nameof(KnownResamplers.Lanczos5), - nameof(KnownResamplers.Lanczos8), - nameof(KnownResamplers.MitchellNetravali), - nameof(KnownResamplers.NearestNeighbor), - nameof(KnownResamplers.Robidoux), - nameof(KnownResamplers.RobidouxSharp), - nameof(KnownResamplers.Spline), - nameof(KnownResamplers.Triangle), - nameof(KnownResamplers.Welch), + nameof(ResampleMode.Bicubic), + nameof(ResampleMode.Box), + nameof(ResampleMode.CatmullRom), + nameof(ResampleMode.Hermite), + nameof(ResampleMode.Lanczos2), + nameof(ResampleMode.Lanczos3), + nameof(ResampleMode.Lanczos5), + nameof(ResampleMode.Lanczos8), + nameof(ResampleMode.MitchellNetravali), + nameof(ResampleMode.NearestNeighbor), + nameof(ResampleMode.Robidoux), + nameof(ResampleMode.RobidouxSharp), + nameof(ResampleMode.Spline), + nameof(ResampleMode.Triangle), + nameof(ResampleMode.Welch), }; public static readonly TheoryData Transform_DoesNotCreateEdgeArtifacts_ResamplerNames = new TheoryData { - nameof(KnownResamplers.NearestNeighbor), - nameof(KnownResamplers.Triangle), - nameof(KnownResamplers.Bicubic), - nameof(KnownResamplers.Lanczos8), + nameof(ResampleMode.NearestNeighbor), + nameof(ResampleMode.Triangle), + nameof(ResampleMode.Bicubic), + nameof(ResampleMode.Lanczos8), }; public AffineTransformTests(ITestOutputHelper output) @@ -111,7 +113,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms this.PrintMatrix(m); - image.Mutate(i => i.Transform(m, KnownResamplers.Bicubic)); + image.Mutate(i => i.Transform(m, ResampleMode.Bicubic)); string testOutputDetails = $"R({angleDeg})_S({sx},{sy})_T({tx},{ty})"; image.DebugSave(provider, testOutputDetails); @@ -128,7 +130,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms { Matrix3x2 m = this.MakeManuallyCenteredMatrix(angleDeg, s, image); - image.Mutate(i => i.Transform(m, KnownResamplers.Bicubic)); + image.Mutate(i => i.Transform(m, ResampleMode.Bicubic)); string testOutputDetails = $"R({angleDeg})_S({s})"; image.DebugSave(provider, testOutputDetails); @@ -161,7 +163,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms { var m = Matrix3x2.CreateScale(2.0F, 1.5F); - image.Mutate(i => i.Transform(m, KnownResamplers.Spline, rectangle)); + image.Mutate(i => i.Transform(m, ResampleMode.Spline, rectangle)); image.DebugSave(provider); image.CompareToReferenceOutput(provider); @@ -179,7 +181,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms { var m = Matrix3x2.CreateScale(1.0F, 2.0F); - image.Mutate(i => i.Transform(m, KnownResamplers.Spline, rectangle)); + image.Mutate(i => i.Transform(m, ResampleMode.Spline, rectangle)); image.DebugSave(provider); image.CompareToReferenceOutput(provider); @@ -223,7 +225,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms private static IResampler GetResampler(string name) { - PropertyInfo property = typeof(KnownResamplers).GetTypeInfo().GetProperty(name); + PropertyInfo property = typeof(ResampleMode).GetTypeInfo().GetProperty(name); if (property == null) { @@ -236,7 +238,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms private static void VerifyAllPixelsAreWhiteOrTransparent(Image image) where TPixel : struct, IPixel { - TPixel[] data = new TPixel[image.Width * image.Height]; + var data = new TPixel[image.Width * image.Height]; image.Frames.RootFrame.SavePixelData(data); var rgba = default(Rgba32); var white = new Rgb24(255, 255, 255); diff --git a/tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs index 20de25054c..d01e84220e 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs @@ -1,11 +1,15 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.PixelFormats; + using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Transforms { + using SixLabors.ImageSharp.Processing.Transforms; + using SixLabors.ImageSharp.Processing.Transforms.Processors; + public class AutoOrientTests : BaseImageOperationsExtensionTest { [Fact] diff --git a/tests/ImageSharp.Tests/Processing/Transforms/CropTest.cs b/tests/ImageSharp.Tests/Processing/Transforms/CropTest.cs index a001efc417..78b6852e47 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/CropTest.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/CropTest.cs @@ -1,9 +1,9 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Transforms; +using SixLabors.ImageSharp.Processing.Transforms.Processors; using SixLabors.Primitives; using Xunit; @@ -14,10 +14,10 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms [Theory] [InlineData(10, 10)] [InlineData(12, 123)] - public void Crop_Width_height_CropProcessorWithRectangleSet(int width, int height) + public void CropWidthHeightCropProcessorWithRectangleSet(int width, int height) { this.operations.Crop(width, height); - var processor = this.Verify>(); + CropProcessor processor = this.Verify>(); Assert.Equal(new Rectangle(0, 0, width, height), processor.CropRectangle); } @@ -25,13 +25,13 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms [Theory] [InlineData(10, 10, 2, 6)] [InlineData(12, 123, 6, 2)] - public void Crop_Rectangle_CropProcessorWithRectangleSet(int x, int y, int width, int height) + public void CropRectangleCropProcessorWithRectangleSet(int x, int y, int width, int height) { - var rect = new Rectangle(x, y, width, height); - this.operations.Crop(rect); - var processor = this.Verify>(); + var cropRectangle = new Rectangle(x, y, width, height); + this.operations.Crop(cropRectangle); + CropProcessor processor = this.Verify>(); - Assert.Equal(rect, processor.CropRectangle); + Assert.Equal(cropRectangle, processor.CropRectangle); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Transforms/EntropyCropTest.cs b/tests/ImageSharp.Tests/Processing/Transforms/EntropyCropTest.cs index c1cde48794..9c2176b25b 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/EntropyCropTest.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/EntropyCropTest.cs @@ -1,25 +1,24 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Transforms; +using SixLabors.ImageSharp.Processing.Transforms.Processors; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Transforms { public class EntropyCropTest : BaseImageOperationsExtensionTest { - [Theory] - [InlineData(0.5f)] - [InlineData(.2f)] - public void EntropyCrop_threasholdFloat_EntropyCropProcessorWithThreshold(float threashold) + [InlineData(0.5F)] + [InlineData(.2F)] + public void EntropyCropThresholdFloatEntropyCropProcessorWithThreshold(float threshold) { - this.operations.EntropyCrop(threashold); - var processor = this.Verify>(); + this.operations.EntropyCrop(threshold); + EntropyCropProcessor processor = this.Verify>(); - Assert.Equal(threashold, processor.Threshold); + Assert.Equal(threshold, processor.Threshold); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Transforms/FlipTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/FlipTests.cs index 4b3e97d106..0ab9978d1b 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/FlipTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/FlipTests.cs @@ -9,6 +9,9 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Transforms { + using SixLabors.ImageSharp.Processing.Transforms; + using SixLabors.ImageSharp.Processing.Transforms.Processors; + public class FlipTests : BaseImageOperationsExtensionTest { @@ -19,7 +22,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms public void Flip_degreesFloat_RotateProcessorWithAnglesSetAndExpandTrue(FlipType flip) { this.operations.Flip(flip); - var flipProcessor = this.Verify>(); + FlipProcessor flipProcessor = this.Verify>(); Assert.Equal(flip, flipProcessor.FlipType); } diff --git a/tests/ImageSharp.Tests/Processing/Transforms/PadTest.cs b/tests/ImageSharp.Tests/Processing/Transforms/PadTest.cs index a9c2922d48..6d7816f59d 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/PadTest.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/PadTest.cs @@ -1,14 +1,14 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Processors; - +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Transforms.Resamplers; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Transforms { - + using SixLabors.ImageSharp.Processing.Transforms; + using SixLabors.ImageSharp.Processing.Transforms.Processors; public class PadTest : BaseImageOperationsExtensionTest { @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms { int width = 500; int height = 565; - IResampler sampler = KnownResamplers.NearestNeighbor; + IResampler sampler = ResampleMode.NearestNeighbor; this.operations.Pad(width, height); ResizeProcessor resizeProcessor = this.Verify>(); diff --git a/tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs index b51d342cf1..853f4b3e65 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs @@ -1,14 +1,15 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Transforms; +using SixLabors.ImageSharp.Processing.Transforms.Processors; +using SixLabors.ImageSharp.Processing.Transforms.Resamplers; using SixLabors.Primitives; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Transforms { - using SixLabors.ImageSharp.Processing.Processors; - public class ResizeTests : BaseImageOperationsExtensionTest { [Fact] @@ -28,7 +29,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms { int width = 50; int height = 100; - IResampler sampler = KnownResamplers.Lanczos3; + IResampler sampler = ResampleMode.Lanczos3; this.operations.Resize(width, height, sampler); ResizeProcessor resizeProcessor = this.Verify>(); @@ -42,7 +43,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms { int width = 50; int height = 100; - IResampler sampler = KnownResamplers.Lanczos3; + IResampler sampler = ResampleMode.Lanczos3; bool compand = true; // ReSharper disable once ConditionIsAlwaysTrueOrFalse @@ -60,7 +61,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms { int width = 50; int height = 100; - IResampler sampler = KnownResamplers.Lanczos3; + IResampler sampler = ResampleMode.Lanczos3; bool compand = true; ResizeMode mode = ResizeMode.Stretch; diff --git a/tests/ImageSharp.Tests/Processing/Transforms/RotateFlipTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/RotateFlipTests.cs index 75d7067702..3d443b70c3 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/RotateFlipTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/RotateFlipTests.cs @@ -1,17 +1,15 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Transforms; +using SixLabors.ImageSharp.Processing.Transforms.Processors; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Transforms { public class RotateFlipTests : BaseImageOperationsExtensionTest { - [Theory] [InlineData(RotateType.None, FlipType.None, 0)] [InlineData(RotateType.Rotate90, FlipType.None, 90)] @@ -25,7 +23,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms [InlineData(RotateType.Rotate90, FlipType.Vertical, 90)] [InlineData(RotateType.Rotate180, FlipType.Vertical, 180)] [InlineData(RotateType.Rotate270, FlipType.Vertical, 270)] - public void Rotate_degreesFloat_RotateProcessorWithAnglesSetrue(RotateType angle, FlipType flip, float expectedAngle) + public void RotateDegreesFloatRotateProcessorWithAnglesSet(RotateType angle, FlipType flip, float expectedAngle) { this.operations.RotateFlip(angle, flip); RotateProcessor rotateProcessor = this.Verify>(0); diff --git a/tests/ImageSharp.Tests/Processing/Transforms/RotateTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/RotateTests.cs index a990fa88ca..742f633c08 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/RotateTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/RotateTests.cs @@ -1,12 +1,16 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Transforms { + using SixLabors.ImageSharp.Processing.Transforms; + using SixLabors.ImageSharp.Processing.Transforms.Processors; + public class RotateTests : BaseImageOperationsExtensionTest { [Theory] @@ -25,12 +29,12 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms [InlineData(RotateType.Rotate90, 90)] [InlineData(RotateType.Rotate180, 180)] [InlineData(RotateType.Rotate270, 270)] - public void RotateRotateTypeRotateProcessorWithAnglesConvertedFromEnum(RotateType angle, float expectedangle) + public void RotateRotateTypeRotateProcessorWithAnglesConvertedFromEnum(RotateType angle, float expectedAngle) { this.operations.Rotate(angle); // is this api needed ??? RotateProcessor processor = this.Verify>(); - Assert.Equal(expectedangle, processor.Degrees); + Assert.Equal(expectedAngle, processor.Degrees); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Transforms/SkewTest.cs b/tests/ImageSharp.Tests/Processing/Transforms/SkewTest.cs index d2cc5764ed..bd0dfacd98 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/SkewTest.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/SkewTest.cs @@ -1,11 +1,15 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Transforms { + using SixLabors.ImageSharp.Processing.Transforms; + using SixLabors.ImageSharp.Processing.Transforms.Processors; + public class SkewTest : BaseImageOperationsExtensionTest { [Fact] diff --git a/tests/ImageSharp.Tests/Processing/Transforms/TransformsHelpersTest.cs b/tests/ImageSharp.Tests/Processing/Transforms/TransformsHelpersTest.cs index c5b6b1ad72..3e92f0e1cb 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/TransformsHelpersTest.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/TransformsHelpersTest.cs @@ -7,6 +7,8 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Transforms { + using SixLabors.ImageSharp.Processing.Transforms; + public class TransformsHelpersTest { [Fact] diff --git a/tests/ImageSharp.Tests/Quantization/QuantizedImageTests.cs b/tests/ImageSharp.Tests/Quantization/QuantizedImageTests.cs index 18fd29237c..8ca04ac23c 100644 --- a/tests/ImageSharp.Tests/Quantization/QuantizedImageTests.cs +++ b/tests/ImageSharp.Tests/Quantization/QuantizedImageTests.cs @@ -1,7 +1,7 @@ namespace SixLabors.ImageSharp.Tests { using SixLabors.ImageSharp.PixelFormats; - using SixLabors.ImageSharp.Quantizers; + using SixLabors.ImageSharp.Processing.Quantization; using Xunit; @@ -33,7 +33,7 @@ foreach (ImageFrame frame in image.Frames) { - QuantizedImage quantized = quantizer.Quantize(frame, 256); + QuantizedFrame quantized = quantizer.Quantize(frame, 256); int index = this.GetTransparentIndex(quantized); Assert.Equal(index, quantized.Pixels[0]); @@ -55,7 +55,7 @@ foreach (ImageFrame frame in image.Frames) { - QuantizedImage quantized = quantizer.Quantize(frame, 256); + QuantizedFrame quantized = quantizer.Quantize(frame, 256); int index = this.GetTransparentIndex(quantized); Assert.Equal(index, quantized.Pixels[0]); @@ -77,7 +77,7 @@ foreach (ImageFrame frame in image.Frames) { - QuantizedImage quantized = quantizer.Quantize(frame, 256); + QuantizedFrame quantized = quantizer.Quantize(frame, 256); int index = this.GetTransparentIndex(quantized); Assert.Equal(index, quantized.Pixels[0]); @@ -85,7 +85,7 @@ } } - private int GetTransparentIndex(QuantizedImage quantized) + private int GetTransparentIndex(QuantizedFrame quantized) where TPixel : struct, IPixel { // Transparent pixels are much more likely to be found at the end of a palette diff --git a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataMatrix.cs b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataMatrix.cs index 8e4b7d3d5b..02bda3a0bb 100644 --- a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataMatrix.cs +++ b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataMatrix.cs @@ -6,6 +6,8 @@ using SixLabors.ImageSharp.Memory; namespace SixLabors.ImageSharp.Tests { + using SixLabors.ImageSharp.Primitives; + internal static class IccTestDataMatrix { #region 2D @@ -42,12 +44,12 @@ namespace SixLabors.ImageSharp.Tests /// /// 3x3 Matrix /// - public static readonly Fast2DArray Single_Fast2DArray_ValGrad = new Fast2DArray(Single_2DArray_ValGrad); + public static readonly DenseMatrix Single_DenseMatrix_ValGrad = new DenseMatrix(Single_2DArray_ValGrad); /// /// 3x3 Matrix /// - public static readonly Fast2DArray Single_Fast2DArray_ValIdentity = new Fast2DArray(Single_2DArray_ValIdentity); + public static readonly DenseMatrix Single_DenseMatrix_ValIdentity = new DenseMatrix(Single_2DArray_ValIdentity); /// /// 3x3 Matrix @@ -110,11 +112,11 @@ namespace SixLabors.ImageSharp.Tests new object[] { Single_2D_Grad, 3, 3, true, Single_2DArray_ValGrad }, }; - public static readonly object[][] Matrix2D_Fast2DArrayTestData = + public static readonly object[][] Matrix2D_DenseMatrixTestData = { - new object[] { Fix16_2D_Grad, 3, 3, false, Single_Fast2DArray_ValGrad }, - new object[] { Fix16_2D_Identity, 3, 3, false, Single_Fast2DArray_ValIdentity }, - new object[] { Single_2D_Grad, 3, 3, true, Single_Fast2DArray_ValGrad }, + new object[] { Fix16_2D_Grad, 3, 3, false, Single_DenseMatrix_ValGrad }, + new object[] { Fix16_2D_Identity, 3, 3, false, Single_DenseMatrix_ValIdentity }, + new object[] { Single_2D_Grad, 3, 3, true, Single_DenseMatrix_ValGrad }, }; public static readonly object[][] Matrix2D_Matrix4x4TestData = diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ExactImageComparer.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ExactImageComparer.cs index dbe2523661..32ff87be63 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ExactImageComparer.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ExactImageComparer.cs @@ -3,7 +3,6 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison using System; using System.Collections.Generic; using SixLabors.ImageSharp.Advanced; - using SixLabors.ImageSharp.Helpers; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs index 920e633795..ca7d7c6a86 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Linq; -using SixLabors.ImageSharp.Helpers; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/PixelDifference.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/PixelDifference.cs index fcfb31d682..97886fdec3 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/PixelDifference.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/PixelDifference.cs @@ -1,4 +1,6 @@ -namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison +using SixLabors.ImageSharp.PixelFormats; + +namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison { using SixLabors.Primitives; diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs index e68a1fbfea..52ea7e45d7 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs @@ -5,7 +5,6 @@ using System.Runtime.CompilerServices; using SixLabors.ImageSharp.Advanced; - using SixLabors.ImageSharp.Helpers; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/SolidProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/SolidProvider.cs index 32860d2a4d..30902b4b0e 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/SolidProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/SolidProvider.cs @@ -4,11 +4,15 @@ using System; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Drawing; +using SixLabors.ImageSharp.Processing.Overlays; using Xunit.Abstractions; namespace SixLabors.ImageSharp.Tests { + using SixLabors.ImageSharp.Processing; + /// /// Provides instances for parametric unit tests. /// diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs index 1352a2476a..0f96348375 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs @@ -13,6 +13,8 @@ namespace SixLabors.ImageSharp.Tests { using Castle.Core.Internal; + using SixLabors.ImageSharp.Processing; + public interface ITestImageProvider { PixelTypes PixelType { get; } diff --git a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs index f03f9db09a..3df71a08af 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs @@ -17,6 +17,7 @@ namespace SixLabors.ImageSharp.Tests using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.MetaData; + using SixLabors.ImageSharp.Processing; using Xunit; diff --git a/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs b/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs index dd033ae7c8..d31094085b 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs @@ -10,6 +10,7 @@ using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Tests { + using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using SixLabors.Primitives; diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/ImageComparerTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/ImageComparerTests.cs index 3f8ec05568..1e768637e8 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/ImageComparerTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/ImageComparerTests.cs @@ -13,6 +13,8 @@ namespace SixLabors.ImageSharp.Tests using Xunit; using Xunit.Abstractions; + using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Transforms; public class ImageComparerTests { diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/ReferenceCodecTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/ReferenceCodecTests.cs index c67e4e06bf..6ff935b546 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/ReferenceCodecTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/ReferenceCodecTests.cs @@ -3,6 +3,7 @@ namespace SixLabors.ImageSharp.Tests using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats.Png; using SixLabors.ImageSharp.PixelFormats; + using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs; diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs index fe5af24d26..1e58b7097a 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs @@ -12,6 +12,8 @@ using Xunit.Abstractions; namespace SixLabors.ImageSharp.Tests { + using SixLabors.ImageSharp.Processing.Effects; + public class TestUtilityExtensionsTests { public TestUtilityExtensionsTests(ITestOutputHelper output) diff --git a/tests/Images/External b/tests/Images/External index 653f0c7e3c..e9f33352b7 160000 --- a/tests/Images/External +++ b/tests/Images/External @@ -1 +1 @@ -Subproject commit 653f0c7e3c84657f68dd46e5a380186b3696b956 +Subproject commit e9f33352b77a5176508d2d5dcafbd1bd33805530