diff --git a/ImageSharp.sln b/ImageSharp.sln index 545f9fac3..c6ab33377 100644 --- a/ImageSharp.sln +++ b/ImageSharp.sln @@ -15,7 +15,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionIt build\appveyor-semver.ps1 = build\appveyor-semver.ps1 appveyor.yml = appveyor.yml CodeCoverage.runsettings = CodeCoverage.runsettings + contributing.md = contributing.md build\dotnet-latest.ps1 = build\dotnet-latest.ps1 + features.md = features.md global.json = global.json build\package.json = build\package.json README.md = README.md diff --git a/README.md b/README.md index 4c6d1ef96..98f918c56 100644 --- a/README.md +++ b/README.md @@ -197,13 +197,13 @@ Setting individual pixel values is perfomed as follows: ```csharp Image image = new Image(400, 400); -using (PixelAccessor pixels = image.Lock()) +using (var pixels = image.Lock()) { pixels[200, 200] = Color.White; } ``` -For advanced usage the `Image` and `PixelAccessor` classes are available allowing developers to implement their own color models in the same manner as Microsoft XNA Game Studio and MonoGame. +For advanced usage the `Image` and `PixelAccessor` classes are available allowing developers to implement their own color models in the same manner as Microsoft XNA Game Studio and MonoGame. All in all this should allow image processing to be much more accessible to developers which has always been my goal from the start. diff --git a/src/ImageSharp/Colors/PackedPixel/IPackedPixel.cs b/src/ImageSharp/Colors/PackedPixel/IPackedPixel.cs index 08257fa68..f9b8dc0a2 100644 --- a/src/ImageSharp/Colors/PackedPixel/IPackedPixel.cs +++ b/src/ImageSharp/Colors/PackedPixel/IPackedPixel.cs @@ -8,11 +8,18 @@ namespace ImageSharp using System; /// - /// An interface that represents a packed pixel type. + /// An interface that represents a generic packed pixel type. /// /// The packed format. uint, long, float. - public interface IPackedPixel : IPackedVector, IPackedBytes + public interface IPackedPixel : IPackedPixel, IPackedVector where TPacked : struct, IEquatable { } -} + + /// + /// An interface that represents a packed pixel type. + /// + public interface IPackedPixel : IPackedVector, IPackedBytes + { + } +} \ No newline at end of file diff --git a/src/ImageSharp/Colors/PackedPixel/IPackedVector.cs b/src/ImageSharp/Colors/PackedPixel/IPackedVector.cs index 32f06e271..4d9a89712 100644 --- a/src/ImageSharp/Colors/PackedPixel/IPackedVector.cs +++ b/src/ImageSharp/Colors/PackedPixel/IPackedVector.cs @@ -40,4 +40,4 @@ namespace ImageSharp /// The . Vector4 ToVector4(); } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Common/Extensions/ArrayExtensions.cs b/src/ImageSharp/Common/Extensions/ArrayExtensions.cs index 8a1a641b4..be3d3f1dc 100644 --- a/src/ImageSharp/Common/Extensions/ArrayExtensions.cs +++ b/src/ImageSharp/Common/Extensions/ArrayExtensions.cs @@ -16,16 +16,14 @@ namespace ImageSharp /// Locks the pixel buffer providing access to the pixels. /// /// The pixel format. - /// The packed format. uint, long, float. /// The pixel buffer. /// Gets the width of the image represented by the pixel buffer. /// The height of the image represented by the pixel buffer. - /// The - public static PixelAccessor Lock(this TColor[] pixels, int width, int height) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The + public static PixelAccessor Lock(this TColor[] pixels, int width, int height) + where TColor : struct, IPackedPixel, IEquatable { - return new PixelAccessor(width, height, pixels); + return new PixelAccessor(width, height, pixels); } } } \ No newline at end of file diff --git a/src/ImageSharp/Common/Helpers/ImageMaths.cs b/src/ImageSharp/Common/Helpers/ImageMaths.cs index d11da5e34..99212346a 100644 --- a/src/ImageSharp/Common/Helpers/ImageMaths.cs +++ b/src/ImageSharp/Common/Helpers/ImageMaths.cs @@ -157,16 +157,14 @@ namespace ImageSharp /// than the given one. /// /// The pixel format. - /// The packed format. uint, long, float. /// The to search within. /// The color component value to remove. /// The channel to test against. /// /// The . /// - public static Rectangle GetFilteredBoundingRectangle(ImageBase bitmap, float componentValue, RgbaComponent channel = RgbaComponent.B) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Rectangle GetFilteredBoundingRectangle(ImageBase bitmap, float componentValue, RgbaComponent channel = RgbaComponent.B) + where TColor : struct, IPackedPixel, IEquatable { const float Epsilon = .00001f; int width = bitmap.Width; @@ -174,7 +172,7 @@ namespace ImageSharp Point topLeft = default(Point); Point bottomRight = default(Point); - Func, int, int, float, bool> delegateFunc; + Func, int, int, float, bool> delegateFunc; // Determine which channel to check against switch (channel) @@ -196,7 +194,7 @@ namespace ImageSharp break; } - Func, int> getMinY = pixels => + Func, int> getMinY = pixels => { for (int y = 0; y < height; y++) { @@ -212,7 +210,7 @@ namespace ImageSharp return 0; }; - Func, int> getMaxY = pixels => + Func, int> getMaxY = pixels => { for (int y = height - 1; y > -1; y--) { @@ -228,7 +226,7 @@ namespace ImageSharp return height; }; - Func, int> getMinX = pixels => + Func, int> getMinX = pixels => { for (int x = 0; x < width; x++) { @@ -244,7 +242,7 @@ namespace ImageSharp return 0; }; - Func, int> getMaxX = pixels => + Func, int> getMaxX = pixels => { for (int x = width - 1; x > -1; x--) { @@ -260,7 +258,7 @@ namespace ImageSharp return height; }; - using (PixelAccessor bitmapPixels = bitmap.Lock()) + using (PixelAccessor bitmapPixels = bitmap.Lock()) { topLeft.Y = getMinY(bitmapPixels); topLeft.X = getMinX(bitmapPixels); diff --git a/src/ImageSharp/Drawing/Brushes/Brushes.cs b/src/ImageSharp/Drawing/Brushes/Brushes.cs index 26ac1fc00..e8269848c 100644 --- a/src/ImageSharp/Drawing/Brushes/Brushes.cs +++ b/src/ImageSharp/Drawing/Brushes/Brushes.cs @@ -25,7 +25,7 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// A Brush public static PatternBrush Percent10(Color foreColor) - => new PatternBrush(Brushes.Percent10(foreColor, Color.Transparent)); + => new PatternBrush(Brushes.Percent10(foreColor, Color.Transparent)); /// /// Create as brush that will paint a Percent10 Hatch Pattern with @@ -35,7 +35,7 @@ namespace ImageSharp.Drawing.Brushes /// Color of the background. /// A Brush public static PatternBrush Percent10(Color foreColor, Color backColor) - => new PatternBrush(Brushes.Percent10(foreColor, backColor)); + => new PatternBrush(Brushes.Percent10(foreColor, backColor)); /// /// Create as brush that will paint a Percent20 Hatch Pattern with @@ -44,7 +44,7 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// A Brush public static PatternBrush Percent20(Color foreColor) - => new PatternBrush(Brushes.Percent20(foreColor, Color.Transparent)); + => new PatternBrush(Brushes.Percent20(foreColor, Color.Transparent)); /// /// Create as brush that will paint a Percent20 Hatch Pattern with @@ -54,7 +54,7 @@ namespace ImageSharp.Drawing.Brushes /// Color of the background. /// A Brush public static PatternBrush Percent20(Color foreColor, Color backColor) - => new PatternBrush(Brushes.Percent20(foreColor, backColor)); + => new PatternBrush(Brushes.Percent20(foreColor, backColor)); /// /// Create as brush that will paint a Horizontal Hatch Pattern with @@ -63,7 +63,7 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// A Brush public static PatternBrush Horizontal(Color foreColor) - => new PatternBrush(Brushes.Horizontal(foreColor, Color.Transparent)); + => new PatternBrush(Brushes.Horizontal(foreColor, Color.Transparent)); /// /// Create as brush that will paint a Horizontal Hatch Pattern with @@ -73,7 +73,7 @@ namespace ImageSharp.Drawing.Brushes /// Color of the background. /// A Brush public static PatternBrush Horizontal(Color foreColor, Color backColor) - => new PatternBrush(Brushes.Horizontal(foreColor, backColor)); + => new PatternBrush(Brushes.Horizontal(foreColor, backColor)); /// /// Create as brush that will paint a Min Hatch Pattern with @@ -82,7 +82,7 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// A Brush public static PatternBrush Min(Color foreColor) - => new PatternBrush(Brushes.Min(foreColor, Color.Transparent)); + => new PatternBrush(Brushes.Min(foreColor, Color.Transparent)); /// /// Create as brush that will paint a Min Hatch Pattern with @@ -92,7 +92,7 @@ namespace ImageSharp.Drawing.Brushes /// Color of the background. /// A Brush public static PatternBrush Min(Color foreColor, Color backColor) - => new PatternBrush(Brushes.Min(foreColor, backColor)); + => new PatternBrush(Brushes.Min(foreColor, backColor)); /// /// Create as brush that will paint a Vertical Hatch Pattern with @@ -101,7 +101,7 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// A Brush public static PatternBrush Vertical(Color foreColor) - => new PatternBrush(Brushes.Vertical(foreColor, Color.Transparent)); + => new PatternBrush(Brushes.Vertical(foreColor, Color.Transparent)); /// /// Create as brush that will paint a Vertical Hatch Pattern with @@ -111,7 +111,7 @@ namespace ImageSharp.Drawing.Brushes /// Color of the background. /// A Brush public static PatternBrush Vertical(Color foreColor, Color backColor) - => new PatternBrush(Brushes.Vertical(foreColor, backColor)); + => new PatternBrush(Brushes.Vertical(foreColor, backColor)); /// /// Create as brush that will paint a Forward Diagonal Hatch Pattern with @@ -120,7 +120,7 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// A Brush public static PatternBrush ForwardDiagonal(Color foreColor) - => new PatternBrush(Brushes.ForwardDiagonal(foreColor, Color.Transparent)); + => new PatternBrush(Brushes.ForwardDiagonal(foreColor, Color.Transparent)); /// /// Create as brush that will paint a Forward Diagonal Hatch Pattern with @@ -130,7 +130,7 @@ namespace ImageSharp.Drawing.Brushes /// Color of the background. /// A Brush public static PatternBrush ForwardDiagonal(Color foreColor, Color backColor) - => new PatternBrush(Brushes.ForwardDiagonal(foreColor, backColor)); + => new PatternBrush(Brushes.ForwardDiagonal(foreColor, backColor)); /// /// Create as brush that will paint a Backward Diagonal Hatch Pattern with @@ -139,7 +139,7 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// A Brush public static PatternBrush BackwardDiagonal(Color foreColor) - => new PatternBrush(Brushes.BackwardDiagonal(foreColor, Color.Transparent)); + => new PatternBrush(Brushes.BackwardDiagonal(foreColor, Color.Transparent)); /// /// Create as brush that will paint a Backward Diagonal Hatch Pattern with @@ -149,6 +149,6 @@ namespace ImageSharp.Drawing.Brushes /// Color of the background. /// A Brush public static PatternBrush BackwardDiagonal(Color foreColor, Color backColor) - => new PatternBrush(Brushes.BackwardDiagonal(foreColor, backColor)); + => new PatternBrush(Brushes.BackwardDiagonal(foreColor, backColor)); } } \ No newline at end of file diff --git a/src/ImageSharp/Drawing/Brushes/Brushes{TColor,TPacked}.cs b/src/ImageSharp/Drawing/Brushes/Brushes{TColor}.cs similarity index 73% rename from src/ImageSharp/Drawing/Brushes/Brushes{TColor,TPacked}.cs rename to src/ImageSharp/Drawing/Brushes/Brushes{TColor}.cs index 8bb2c698b..a5cf02b8a 100644 --- a/src/ImageSharp/Drawing/Brushes/Brushes{TColor,TPacked}.cs +++ b/src/ImageSharp/Drawing/Brushes/Brushes{TColor}.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -11,11 +11,9 @@ namespace ImageSharp.Drawing.Brushes /// A collection of methods for creating generic brushes. /// /// The pixel format. - /// The packed format. uint, long, float. /// A Brush - public class Brushes - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class Brushes + where TColor : struct, IPackedPixel, IEquatable { /// /// Percent10 Hatch Pattern @@ -99,8 +97,8 @@ namespace ImageSharp.Drawing.Brushes /// /// The color. /// A Brush - public static SolidBrush Solid(TColor color) - => new SolidBrush(color); + public static SolidBrush Solid(TColor color) + => new SolidBrush(color); /// /// Create as brush that will paint a Percent10 Hatch Pattern within the specified colors @@ -108,8 +106,8 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// Color of the background. /// A Brush - public static PatternBrush Percent10(TColor foreColor, TColor backColor) - => new PatternBrush(foreColor, backColor, Percent10Pattern); + public static PatternBrush Percent10(TColor foreColor, TColor backColor) + => new PatternBrush(foreColor, backColor, Percent10Pattern); /// /// Create as brush that will paint a Percent20 Hatch Pattern within the specified colors @@ -117,8 +115,8 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// Color of the background. /// A Brush - public static PatternBrush Percent20(TColor foreColor, TColor backColor) - => new PatternBrush(foreColor, backColor, Percent20Pattern); + public static PatternBrush Percent20(TColor foreColor, TColor backColor) + => new PatternBrush(foreColor, backColor, Percent20Pattern); /// /// Create as brush that will paint a Horizontal Hatch Pattern within the specified colors @@ -126,8 +124,8 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// Color of the background. /// A Brush - public static PatternBrush Horizontal(TColor foreColor, TColor backColor) - => new PatternBrush(foreColor, backColor, HorizontalPattern); + public static PatternBrush Horizontal(TColor foreColor, TColor backColor) + => new PatternBrush(foreColor, backColor, HorizontalPattern); /// /// Create as brush that will paint a Min Hatch Pattern within the specified colors @@ -135,8 +133,8 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// Color of the background. /// A Brush - public static PatternBrush Min(TColor foreColor, TColor backColor) - => new PatternBrush(foreColor, backColor, MinPattern); + public static PatternBrush Min(TColor foreColor, TColor backColor) + => new PatternBrush(foreColor, backColor, MinPattern); /// /// Create as brush that will paint a Vertical Hatch Pattern within the specified colors @@ -144,8 +142,8 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// Color of the background. /// A Brush - public static PatternBrush Vertical(TColor foreColor, TColor backColor) - => new PatternBrush(foreColor, backColor, VerticalPattern); + public static PatternBrush Vertical(TColor foreColor, TColor backColor) + => new PatternBrush(foreColor, backColor, VerticalPattern); /// /// Create as brush that will paint a Forward Diagonal Hatch Pattern within the specified colors @@ -153,8 +151,8 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// Color of the background. /// A Brush - public static PatternBrush ForwardDiagonal(TColor foreColor, TColor backColor) - => new PatternBrush(foreColor, backColor, ForwardDiagonalPattern); + public static PatternBrush ForwardDiagonal(TColor foreColor, TColor backColor) + => new PatternBrush(foreColor, backColor, ForwardDiagonalPattern); /// /// Create as brush that will paint a Backward Diagonal Hatch Pattern within the specified colors @@ -162,7 +160,7 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// Color of the background. /// A Brush - public static PatternBrush BackwardDiagonal(TColor foreColor, TColor backColor) - => new PatternBrush(foreColor, backColor, BackwardDiagonalPattern); + public static PatternBrush BackwardDiagonal(TColor foreColor, TColor backColor) + => new PatternBrush(foreColor, backColor, BackwardDiagonalPattern); } } diff --git a/src/ImageSharp/Drawing/Brushes/IBrush.cs b/src/ImageSharp/Drawing/Brushes/IBrush.cs index 5dc79dc38..7c3f29335 100644 --- a/src/ImageSharp/Drawing/Brushes/IBrush.cs +++ b/src/ImageSharp/Drawing/Brushes/IBrush.cs @@ -13,14 +13,12 @@ namespace ImageSharp.Drawing /// Brush represents a logical configuration of a brush which can be used to source pixel colors /// /// The pixel format. - /// The packed format. uint, long, float. /// - /// A brush is a simple class that will return an that will perform the + /// A brush is a simple class that will return an that will perform the /// logic for converting a pixel location to a . /// - public interface IBrush - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public interface IBrush + where TColor : struct, IPackedPixel, IEquatable { /// /// Creates the applicator for this brush. @@ -31,6 +29,6 @@ namespace ImageSharp.Drawing /// The when being applied to things like shapes would usually be the /// bounding box of the shape not necessarily the bounds of the whole image /// - IBrushApplicator CreateApplicator(RectangleF region); + IBrushApplicator CreateApplicator(RectangleF region); } } \ No newline at end of file diff --git a/src/ImageSharp/Drawing/Brushes/ImageBrush.cs b/src/ImageSharp/Drawing/Brushes/ImageBrush.cs index c76d8657a..a7124bfe8 100644 --- a/src/ImageSharp/Drawing/Brushes/ImageBrush.cs +++ b/src/ImageSharp/Drawing/Brushes/ImageBrush.cs @@ -8,13 +8,13 @@ namespace ImageSharp.Drawing.Brushes /// /// Provides an implementation of a solid brush for painting with repeating images. The brush uses for painting. /// - public class ImageBrush : ImageBrush + public class ImageBrush : ImageBrush { /// /// Initializes a new instance of the class. /// /// The image to paint. - public ImageBrush(IImageBase image) + public ImageBrush(IImageBase image) : base(image) { } diff --git a/src/ImageSharp/Drawing/Brushes/ImageBrush{TColor,TPacked}.cs b/src/ImageSharp/Drawing/Brushes/ImageBrush{TColor}.cs similarity index 78% rename from src/ImageSharp/Drawing/Brushes/ImageBrush{TColor,TPacked}.cs rename to src/ImageSharp/Drawing/Brushes/ImageBrush{TColor}.cs index 9fcb11038..ce15b4a2e 100644 --- a/src/ImageSharp/Drawing/Brushes/ImageBrush{TColor,TPacked}.cs +++ b/src/ImageSharp/Drawing/Brushes/ImageBrush{TColor}.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -14,27 +14,25 @@ namespace ImageSharp.Drawing.Brushes /// Provides an implementation of an image brush for painting images within areas. /// /// The pixel format. - /// The packed format. uint, long, float. - public class ImageBrush : IBrush - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class ImageBrush : IBrush + where TColor : struct, IPackedPixel, IEquatable { /// /// The image to paint. /// - private readonly IImageBase image; + private readonly IImageBase image; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The image. - public ImageBrush(IImageBase image) + public ImageBrush(IImageBase image) { this.image = image; } /// - public IBrushApplicator CreateApplicator(RectangleF region) + public IBrushApplicator CreateApplicator(RectangleF region) { return new ImageBrushApplicator(this.image, region); } @@ -42,12 +40,12 @@ namespace ImageSharp.Drawing.Brushes /// /// The image brush applicator. /// - private class ImageBrushApplicator : IBrushApplicator + private class ImageBrushApplicator : IBrushApplicator { /// /// The source pixel accessor. /// - private readonly PixelAccessor source; + private readonly PixelAccessor source; /// /// The y-length. @@ -73,7 +71,7 @@ namespace ImageSharp.Drawing.Brushes /// /// The region. /// - public ImageBrushApplicator(IImageBase image, RectangleF region) + public ImageBrushApplicator(IImageBase image, RectangleF region) { this.source = image.Lock(); this.xLength = image.Width; diff --git a/src/ImageSharp/Drawing/Brushes/PatternBrush.cs b/src/ImageSharp/Drawing/Brushes/PatternBrush.cs index bd812e1c8..5093a7df0 100644 --- a/src/ImageSharp/Drawing/Brushes/PatternBrush.cs +++ b/src/ImageSharp/Drawing/Brushes/PatternBrush.cs @@ -8,7 +8,7 @@ namespace ImageSharp.Drawing.Brushes /// /// Provides an implementation of a pattern brush for painting patterns. The brush use for painting. /// - public class PatternBrush : PatternBrush + public class PatternBrush : PatternBrush { /// /// Initializes a new instance of the class. @@ -25,7 +25,7 @@ namespace ImageSharp.Drawing.Brushes /// Initializes a new instance of the class. /// /// The brush. - internal PatternBrush(PatternBrush brush) + internal PatternBrush(PatternBrush brush) : base(brush) { } diff --git a/src/ImageSharp/Drawing/Brushes/PatternBrush{TColor,TPacked}.cs b/src/ImageSharp/Drawing/Brushes/PatternBrush{TColor}.cs similarity index 88% rename from src/ImageSharp/Drawing/Brushes/PatternBrush{TColor,TPacked}.cs rename to src/ImageSharp/Drawing/Brushes/PatternBrush{TColor}.cs index 9d18342d9..8ed5f8ae1 100644 --- a/src/ImageSharp/Drawing/Brushes/PatternBrush{TColor,TPacked}.cs +++ b/src/ImageSharp/Drawing/Brushes/PatternBrush{TColor}.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -41,10 +41,8 @@ namespace ImageSharp.Drawing.Brushes /// 00 /// /// The pixel format. - /// The packed format. uint, long, float. - public class PatternBrush : IBrush - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class PatternBrush : IBrush + where TColor : struct, IPackedPixel, IEquatable { /// /// The pattern. @@ -57,7 +55,7 @@ namespace ImageSharp.Drawing.Brushes private readonly int stride; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// Color of the fore. /// Color of the back. @@ -87,17 +85,17 @@ namespace ImageSharp.Drawing.Brushes } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The brush. - internal PatternBrush(PatternBrush brush) + internal PatternBrush(PatternBrush brush) { this.pattern = brush.pattern; this.stride = brush.stride; } /// - public IBrushApplicator CreateApplicator(RectangleF region) + public IBrushApplicator CreateApplicator(RectangleF region) { return new PatternBrushApplicator(this.pattern, this.stride); } @@ -105,7 +103,7 @@ namespace ImageSharp.Drawing.Brushes /// /// The pattern brush applicator. /// - private class PatternBrushApplicator : IBrushApplicator + private class PatternBrushApplicator : IBrushApplicator { /// /// The patter x-length. diff --git a/src/ImageSharp/Drawing/Brushes/Processors/IBrushApplicator.cs b/src/ImageSharp/Drawing/Brushes/Processors/IBrushApplicator.cs index d762638b8..9b09f87db 100644 --- a/src/ImageSharp/Drawing/Brushes/Processors/IBrushApplicator.cs +++ b/src/ImageSharp/Drawing/Brushes/Processors/IBrushApplicator.cs @@ -12,11 +12,9 @@ namespace ImageSharp.Drawing.Processors /// primitive that converts a point in to a color for discovering the fill color based on an implementation /// /// The pixel format. - /// The packed format. uint, long, float. /// - public interface IBrushApplicator : IDisposable // disposable will be required if/when there is an ImageBrush - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public interface IBrushApplicator : IDisposable // disposable will be required if/when there is an ImageBrush + where TColor : struct, IPackedPixel, IEquatable { /// /// Gets the color for a single pixel. diff --git a/src/ImageSharp/Drawing/Brushes/SolidBrush.cs b/src/ImageSharp/Drawing/Brushes/SolidBrush.cs index 7cac3fa65..123d8a7e3 100644 --- a/src/ImageSharp/Drawing/Brushes/SolidBrush.cs +++ b/src/ImageSharp/Drawing/Brushes/SolidBrush.cs @@ -8,7 +8,7 @@ namespace ImageSharp.Drawing.Brushes /// /// Provides an implementation of a solid brush for painting solid color areas. The brush uses for painting. /// - public class SolidBrush : SolidBrush + public class SolidBrush : SolidBrush { /// /// Initializes a new instance of the class. diff --git a/src/ImageSharp/Drawing/Brushes/SolidBrush{TColor,TPacked}.cs b/src/ImageSharp/Drawing/Brushes/SolidBrush{TColor}.cs similarity index 81% rename from src/ImageSharp/Drawing/Brushes/SolidBrush{TColor,TPacked}.cs rename to src/ImageSharp/Drawing/Brushes/SolidBrush{TColor}.cs index 351373b23..6b74580d8 100644 --- a/src/ImageSharp/Drawing/Brushes/SolidBrush{TColor,TPacked}.cs +++ b/src/ImageSharp/Drawing/Brushes/SolidBrush{TColor}.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -14,10 +14,8 @@ namespace ImageSharp.Drawing.Brushes /// Provides an implementation of a solid brush for painting solid color areas. /// /// The pixel format. - /// The packed format. uint, long, float. - public class SolidBrush : IBrush - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class SolidBrush : IBrush + where TColor : struct, IPackedPixel, IEquatable { /// /// The color to paint. @@ -25,7 +23,7 @@ namespace ImageSharp.Drawing.Brushes private readonly TColor color; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The color. public SolidBrush(TColor color) @@ -42,7 +40,7 @@ namespace ImageSharp.Drawing.Brushes public TColor Color => this.color; /// - public IBrushApplicator CreateApplicator(RectangleF region) + public IBrushApplicator CreateApplicator(RectangleF region) { return new SolidBrushApplicator(this.color); } @@ -50,7 +48,7 @@ namespace ImageSharp.Drawing.Brushes /// /// The solid brush applicator. /// - private class SolidBrushApplicator : IBrushApplicator + private class SolidBrushApplicator : IBrushApplicator { /// /// The solid color. diff --git a/src/ImageSharp/Drawing/Draw.cs b/src/ImageSharp/Drawing/Draw.cs index 0f58c5727..14f3db44d 100644 --- a/src/ImageSharp/Drawing/Draw.cs +++ b/src/ImageSharp/Drawing/Draw.cs @@ -15,7 +15,7 @@ namespace ImageSharp using Drawing.Shapes; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -23,7 +23,6 @@ namespace ImageSharp /// Draws the outline of the polygon with the provided pen. /// /// The type of the color. - /// The type of the packed. /// The source. /// The pen. /// The shape. @@ -31,25 +30,22 @@ namespace ImageSharp /// /// The Image /// - public static Image DrawPolygon(this Image source, IPen pen, IShape shape, GraphicsOptions options) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image DrawPolygon(this Image source, IPen pen, IShape shape, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable { - return source.Process(new DrawPathProcessor(pen, shape, options)); + return source.Process(new DrawPathProcessor(pen, shape, options)); } /// /// Draws the outline of the polygon with the provided pen. /// /// The type of the color. - /// The type of the packed. /// The source. /// The pen. /// The shape. /// The Image - public static Image DrawPolygon(this Image source, IPen pen, IShape shape) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image DrawPolygon(this Image source, IPen pen, IShape shape) + where TColor : struct, IPackedPixel, IEquatable { return source.DrawPolygon(pen, shape, GraphicsOptions.Default); } @@ -58,7 +54,6 @@ namespace ImageSharp /// Draws the outline of the polygon with the provided brush at the provided thickness. /// /// The type of the color. - /// The type of the packed. /// The source. /// The brush. /// The thickness. @@ -67,35 +62,31 @@ namespace ImageSharp /// /// The Image /// - public static Image DrawPolygon(this Image source, IBrush brush, float thickness, IShape shape, GraphicsOptions options) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image DrawPolygon(this Image source, IBrush brush, float thickness, IShape shape, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable { - return source.DrawPolygon(new Pen(brush, thickness), shape, options); + return source.DrawPolygon(new Pen(brush, thickness), shape, options); } /// /// Draws the outline of the polygon with the provided brush at the provided thickness. /// /// The type of the color. - /// The type of the packed. /// The source. /// The brush. /// The thickness. /// The shape. /// The Image - public static Image DrawPolygon(this Image source, IBrush brush, float thickness, IShape shape) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image DrawPolygon(this Image source, IBrush brush, float thickness, IShape shape) + where TColor : struct, IPackedPixel, IEquatable { - return source.DrawPolygon(new Pen(brush, thickness), shape); + return source.DrawPolygon(new Pen(brush, thickness), shape); } /// /// Draws the outline of the polygon with the provided brush at the provided thickness. /// /// The type of the color. - /// The type of the packed. /// The source. /// The color. /// The thickness. @@ -104,35 +95,31 @@ namespace ImageSharp /// /// The Image /// - public static Image DrawPolygon(this Image source, TColor color, float thickness, IShape shape, GraphicsOptions options) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image DrawPolygon(this Image source, TColor color, float thickness, IShape shape, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable { - return source.DrawPolygon(new SolidBrush(color), thickness, shape, options); + return source.DrawPolygon(new SolidBrush(color), thickness, shape, options); } /// /// Draws the outline of the polygon with the provided brush at the provided thickness. /// /// The type of the color. - /// The type of the packed. /// The source. /// The color. /// The thickness. /// The shape. /// The Image - public static Image DrawPolygon(this Image source, TColor color, float thickness, IShape shape) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image DrawPolygon(this Image source, TColor color, float thickness, IShape shape) + where TColor : struct, IPackedPixel, IEquatable { - return source.DrawPolygon(new SolidBrush(color), thickness, shape); + return source.DrawPolygon(new SolidBrush(color), thickness, shape); } /// /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness. /// /// The type of the color. - /// The type of the packed. /// The source. /// The brush. /// The thickness. @@ -141,52 +128,46 @@ namespace ImageSharp /// /// The Image /// - public static Image DrawPolygon(this Image source, IBrush brush, float thickness, Vector2[] points, GraphicsOptions options) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image DrawPolygon(this Image source, IBrush brush, float thickness, Vector2[] points, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable { - return source.DrawPolygon(new Pen(brush, thickness), new Polygon(new LinearLineSegment(points)), options); + return source.DrawPolygon(new Pen(brush, thickness), new Polygon(new LinearLineSegment(points)), options); } /// /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness. /// /// The type of the color. - /// The type of the packed. /// The source. /// The brush. /// The thickness. /// The points. /// The Image - public static Image DrawPolygon(this Image source, IBrush brush, float thickness, Vector2[] points) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image DrawPolygon(this Image source, IBrush brush, float thickness, Vector2[] points) + where TColor : struct, IPackedPixel, IEquatable { - return source.DrawPolygon(new Pen(brush, thickness), new Polygon(new LinearLineSegment(points))); + return source.DrawPolygon(new Pen(brush, thickness), new Polygon(new LinearLineSegment(points))); } /// /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness. /// /// The type of the color. - /// The type of the packed. /// The source. /// The color. /// The thickness. /// The points. /// The Image - public static Image DrawPolygon(this Image source, TColor color, float thickness, Vector2[] points) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image DrawPolygon(this Image source, TColor color, float thickness, Vector2[] points) + where TColor : struct, IPackedPixel, IEquatable { - return source.DrawPolygon(new SolidBrush(color), thickness, points); + return source.DrawPolygon(new SolidBrush(color), thickness, points); } /// /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness. /// /// The type of the color. - /// The type of the packed. /// The source. /// The color. /// The thickness. @@ -195,18 +176,16 @@ namespace ImageSharp /// /// The Image /// - public static Image DrawPolygon(this Image source, TColor color, float thickness, Vector2[] points, GraphicsOptions options) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image DrawPolygon(this Image source, TColor color, float thickness, Vector2[] points, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable { - return source.DrawPolygon(new SolidBrush(color), thickness, points, options); + return source.DrawPolygon(new SolidBrush(color), thickness, points, options); } /// /// Draws the provided Points as a closed Linear Polygon with the provided Pen. /// /// The type of the color. - /// The type of the packed. /// The source. /// The pen. /// The points. @@ -214,9 +193,8 @@ namespace ImageSharp /// /// The Image /// - public static Image DrawPolygon(this Image source, IPen pen, Vector2[] points, GraphicsOptions options) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image DrawPolygon(this Image source, IPen pen, Vector2[] points, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable { return source.DrawPolygon(pen, new Polygon(new LinearLineSegment(points)), options); } @@ -225,14 +203,12 @@ namespace ImageSharp /// Draws the provided Points as a closed Linear Polygon with the provided Pen. /// /// The type of the color. - /// The type of the packed. /// The source. /// The pen. /// The points. /// The Image - public static Image DrawPolygon(this Image source, IPen pen, Vector2[] points) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image DrawPolygon(this Image source, IPen pen, Vector2[] points) + where TColor : struct, IPackedPixel, IEquatable { return source.DrawPolygon(pen, new Polygon(new LinearLineSegment(points))); } @@ -241,7 +217,6 @@ namespace ImageSharp /// Draws the path with the provided pen. /// /// The type of the color. - /// The type of the packed. /// The source. /// The pen. /// The path. @@ -249,34 +224,30 @@ namespace ImageSharp /// /// The Image /// - public static Image DrawPath(this Image source, IPen pen, IPath path, GraphicsOptions options) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image DrawPath(this Image source, IPen pen, IPath path, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable { - return source.Process(new DrawPathProcessor(pen, path, options)); + return source.Process(new DrawPathProcessor(pen, path, options)); } /// /// Draws the path with the provided pen. /// /// The type of the color. - /// The type of the packed. /// The source. /// The pen. /// The path. /// The Image - public static Image DrawPath(this Image source, IPen pen, IPath path) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image DrawPath(this Image source, IPen pen, IPath path) + where TColor : struct, IPackedPixel, IEquatable { - return source.Process(new DrawPathProcessor(pen, path, GraphicsOptions.Default)); + return source.Process(new DrawPathProcessor(pen, path, GraphicsOptions.Default)); } /// /// Draws the path with the bursh at the privdied thickness. /// /// The type of the color. - /// The type of the packed. /// The source. /// The brush. /// The thickness. @@ -285,35 +256,31 @@ namespace ImageSharp /// /// The Image /// - public static Image DrawPath(this Image source, IBrush brush, float thickness, IPath path, GraphicsOptions options) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image DrawPath(this Image source, IBrush brush, float thickness, IPath path, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable { - return source.DrawPath(new Pen(brush, thickness), path, options); + return source.DrawPath(new Pen(brush, thickness), path, options); } /// /// Draws the path with the bursh at the privdied thickness. /// /// The type of the color. - /// The type of the packed. /// The source. /// The brush. /// The thickness. /// The path. /// The Image - public static Image DrawPath(this Image source, IBrush brush, float thickness, IPath path) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image DrawPath(this Image source, IBrush brush, float thickness, IPath path) + where TColor : struct, IPackedPixel, IEquatable { - return source.DrawPath(new Pen(brush, thickness), path); + return source.DrawPath(new Pen(brush, thickness), path); } /// /// Draws the path with the bursh at the privdied thickness. /// /// The type of the color. - /// The type of the packed. /// The source. /// The color. /// The thickness. @@ -322,35 +289,31 @@ namespace ImageSharp /// /// The Image /// - public static Image DrawPath(this Image source, TColor color, float thickness, IPath path, GraphicsOptions options) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image DrawPath(this Image source, TColor color, float thickness, IPath path, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable { - return source.DrawPath(new SolidBrush(color), thickness, path, options); + return source.DrawPath(new SolidBrush(color), thickness, path, options); } /// /// Draws the path with the bursh at the privdied thickness. /// /// The type of the color. - /// The type of the packed. /// The source. /// The color. /// The thickness. /// The path. /// The Image - public static Image DrawPath(this Image source, TColor color, float thickness, IPath path) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image DrawPath(this Image source, TColor color, float thickness, IPath path) + where TColor : struct, IPackedPixel, IEquatable { - return source.DrawPath(new SolidBrush(color), thickness, path); + return source.DrawPath(new SolidBrush(color), thickness, path); } /// /// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush /// /// The type of the color. - /// The type of the packed. /// The source. /// The brush. /// The thickness. @@ -359,52 +322,46 @@ namespace ImageSharp /// /// The Image /// - public static Image DrawLines(this Image source, IBrush brush, float thickness, Vector2[] points, GraphicsOptions options) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image DrawLines(this Image source, IBrush brush, float thickness, Vector2[] points, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable { - return source.DrawPath(new Pen(brush, thickness), new Path(new LinearLineSegment(points)), options); + return source.DrawPath(new Pen(brush, thickness), new Path(new LinearLineSegment(points)), options); } /// /// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush /// /// The type of the color. - /// The type of the packed. /// The source. /// The brush. /// The thickness. /// The points. /// The Image - public static Image DrawLines(this Image source, IBrush brush, float thickness, Vector2[] points) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image DrawLines(this Image source, IBrush brush, float thickness, Vector2[] points) + where TColor : struct, IPackedPixel, IEquatable { - return source.DrawPath(new Pen(brush, thickness), new Path(new LinearLineSegment(points))); + return source.DrawPath(new Pen(brush, thickness), new Path(new LinearLineSegment(points))); } /// /// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush /// /// The type of the color. - /// The type of the packed. /// The source. /// The color. /// The thickness. /// The points. /// The Image - public static Image DrawLines(this Image source, TColor color, float thickness, Vector2[] points) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image DrawLines(this Image source, TColor color, float thickness, Vector2[] points) + where TColor : struct, IPackedPixel, IEquatable { - return source.DrawLines(new SolidBrush(color), thickness, points); + return source.DrawLines(new SolidBrush(color), thickness, points); } /// /// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush /// /// The type of the color. - /// The type of the packed. /// The source. /// The color. /// The thickness. @@ -413,18 +370,16 @@ namespace ImageSharp /// /// The Image /// - public static Image DrawLines(this Image source, TColor color, float thickness, Vector2[] points, GraphicsOptions options) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image DrawLines(this Image source, TColor color, float thickness, Vector2[] points, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable { - return source.DrawLines(new SolidBrush(color), thickness, points, options); + return source.DrawLines(new SolidBrush(color), thickness, points, options); } /// /// Draws the provided Points as an open Linear path with the supplied pen /// /// The type of the color. - /// The type of the packed. /// The source. /// The pen. /// The points. @@ -432,9 +387,8 @@ namespace ImageSharp /// /// The Image /// - public static Image DrawLines(this Image source, IPen pen, Vector2[] points, GraphicsOptions options) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image DrawLines(this Image source, IPen pen, Vector2[] points, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable { return source.DrawPath(pen, new Path(new LinearLineSegment(points)), options); } @@ -443,14 +397,12 @@ namespace ImageSharp /// Draws the provided Points as an open Linear path with the supplied pen /// /// The type of the color. - /// The type of the packed. /// The source. /// The pen. /// The points. /// The Image - public static Image DrawLines(this Image source, IPen pen, Vector2[] points) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image DrawLines(this Image source, IPen pen, Vector2[] points) + where TColor : struct, IPackedPixel, IEquatable { return source.DrawPath(pen, new Path(new LinearLineSegment(points))); } @@ -459,7 +411,6 @@ namespace ImageSharp /// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush /// /// The type of the color. - /// The type of the packed. /// The source. /// The brush. /// The thickness. @@ -468,52 +419,46 @@ namespace ImageSharp /// /// The Image /// - public static Image DrawBeziers(this Image source, IBrush brush, float thickness, Vector2[] points, GraphicsOptions options) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image DrawBeziers(this Image source, IBrush brush, float thickness, Vector2[] points, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable { - return source.DrawPath(new Pen(brush, thickness), new Path(new BezierLineSegment(points)), options); + return source.DrawPath(new Pen(brush, thickness), new Path(new BezierLineSegment(points)), options); } /// /// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush /// /// The type of the color. - /// The type of the packed. /// The source. /// The brush. /// The thickness. /// The points. /// The Image - public static Image DrawBeziers(this Image source, IBrush brush, float thickness, Vector2[] points) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image DrawBeziers(this Image source, IBrush brush, float thickness, Vector2[] points) + where TColor : struct, IPackedPixel, IEquatable { - return source.DrawPath(new Pen(brush, thickness), new Path(new BezierLineSegment(points))); + return source.DrawPath(new Pen(brush, thickness), new Path(new BezierLineSegment(points))); } /// /// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush /// /// The type of the color. - /// The type of the packed. /// The source. /// The color. /// The thickness. /// The points. /// The Image - public static Image DrawBeziers(this Image source, TColor color, float thickness, Vector2[] points) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image DrawBeziers(this Image source, TColor color, float thickness, Vector2[] points) + where TColor : struct, IPackedPixel, IEquatable { - return source.DrawBeziers(new SolidBrush(color), thickness, points); + return source.DrawBeziers(new SolidBrush(color), thickness, points); } /// /// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush /// /// The type of the color. - /// The type of the packed. /// The source. /// The color. /// The thickness. @@ -522,18 +467,16 @@ namespace ImageSharp /// /// The Image /// - public static Image DrawBeziers(this Image source, TColor color, float thickness, Vector2[] points, GraphicsOptions options) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image DrawBeziers(this Image source, TColor color, float thickness, Vector2[] points, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable { - return source.DrawBeziers(new SolidBrush(color), thickness, points, options); + return source.DrawBeziers(new SolidBrush(color), thickness, points, options); } /// /// Draws the provided Points as an open Bezier path with the supplied pen /// /// The type of the color. - /// The type of the packed. /// The source. /// The pen. /// The points. @@ -541,9 +484,8 @@ namespace ImageSharp /// /// The Image /// - public static Image DrawBeziers(this Image source, IPen pen, Vector2[] points, GraphicsOptions options) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image DrawBeziers(this Image source, IPen pen, Vector2[] points, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable { return source.DrawPath(pen, new Path(new BezierLineSegment(points)), options); } @@ -552,14 +494,12 @@ namespace ImageSharp /// Draws the provided Points as an open Bezier path with the supplied pen /// /// The type of the color. - /// The type of the packed. /// The source. /// The pen. /// The points. /// The Image - public static Image DrawBeziers(this Image source, IPen pen, Vector2[] points) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image DrawBeziers(this Image source, IPen pen, Vector2[] points) + where TColor : struct, IPackedPixel, IEquatable { return source.DrawPath(pen, new Path(new BezierLineSegment(points))); } diff --git a/src/ImageSharp/Drawing/DrawImage.cs b/src/ImageSharp/Drawing/DrawImage.cs index b7e672e0a..db9d01153 100644 --- a/src/ImageSharp/Drawing/DrawImage.cs +++ b/src/ImageSharp/Drawing/DrawImage.cs @@ -18,14 +18,12 @@ namespace ImageSharp /// Draws the given image together with the current one by blending their pixels. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The image to blend with the currently processing image. /// The opacity of the image image to blend. Must be between 0 and 100. - /// The . - public static Image Blend(this Image source, Image image, int percent = 50) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image Blend(this Image source, Image image, int percent = 50) + where TColor : struct, IPackedPixel, IEquatable { return DrawImage(source, image, percent, default(Size), default(Point)); } @@ -36,14 +34,12 @@ namespace ImageSharp /// The image this method extends. /// The image to blend with the currently processing image. /// The pixel format. - /// The packed format. uint, long, float. /// The opacity of the image image to blend. Must be between 0 and 100. /// The size to draw the blended image. /// The location to draw the blended image. - /// The . - public static Image DrawImage(this Image source, Image image, int percent, Size size, Point location) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image DrawImage(this Image source, Image image, int percent, Size size, Point location) + where TColor : struct, IPackedPixel, IEquatable { if (size == default(Size)) { @@ -55,7 +51,7 @@ namespace ImageSharp location = Point.Empty; } - return source.Process(source.Bounds, new DrawImageProcessor(image, size, location, percent)); + return source.Process(source.Bounds, new DrawImageProcessor(image, size, location, percent)); } } } \ No newline at end of file diff --git a/src/ImageSharp/Drawing/Draw_Rectangle.cs b/src/ImageSharp/Drawing/DrawRectangle.cs similarity index 54% rename from src/ImageSharp/Drawing/Draw_Rectangle.cs rename to src/ImageSharp/Drawing/DrawRectangle.cs index 80a0f143b..8b1cd03e8 100644 --- a/src/ImageSharp/Drawing/Draw_Rectangle.cs +++ b/src/ImageSharp/Drawing/DrawRectangle.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -6,17 +6,16 @@ namespace ImageSharp { using System; - using System.Numerics; + using Drawing; using Drawing.Brushes; using Drawing.Paths; using Drawing.Pens; using Drawing.Processors; using Drawing.Shapes; - using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -24,7 +23,6 @@ namespace ImageSharp /// Draws the outline of the polygon with the provided pen. /// /// The type of the color. - /// The type of the packed. /// The source. /// The pen. /// The shape. @@ -32,25 +30,22 @@ namespace ImageSharp /// /// The Image /// - public static Image DrawPolygon(this Image source, IPen pen, RectangleF shape, GraphicsOptions options) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image DrawPolygon(this Image source, IPen pen, RectangleF shape, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable { - return source.Process(new DrawPathProcessor(pen, (IPath)new RectangularPolygon(shape), options)); + return source.Process(new DrawPathProcessor(pen, (IPath)new RectangularPolygon(shape), options)); } /// /// Draws the outline of the polygon with the provided pen. /// /// The type of the color. - /// The type of the packed. /// The source. /// The pen. /// The shape. /// The Image - public static Image DrawPolygon(this Image source, IPen pen, RectangleF shape) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image DrawPolygon(this Image source, IPen pen, RectangleF shape) + where TColor : struct, IPackedPixel, IEquatable { return source.DrawPolygon(pen, shape, GraphicsOptions.Default); } @@ -59,7 +54,6 @@ namespace ImageSharp /// Draws the outline of the polygon with the provided brush at the provided thickness. /// /// The type of the color. - /// The type of the packed. /// The source. /// The brush. /// The thickness. @@ -68,35 +62,31 @@ namespace ImageSharp /// /// The Image /// - public static Image DrawPolygon(this Image source, IBrush brush, float thickness, RectangleF shape, GraphicsOptions options) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image DrawPolygon(this Image source, IBrush brush, float thickness, RectangleF shape, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable { - return source.DrawPolygon(new Pen(brush, thickness), shape, options); + return source.DrawPolygon(new Pen(brush, thickness), shape, options); } /// /// Draws the outline of the polygon with the provided brush at the provided thickness. /// /// The type of the color. - /// The type of the packed. /// The source. /// The brush. /// The thickness. /// The shape. /// The Image - public static Image DrawPolygon(this Image source, IBrush brush, float thickness, RectangleF shape) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image DrawPolygon(this Image source, IBrush brush, float thickness, RectangleF shape) + where TColor : struct, IPackedPixel, IEquatable { - return source.DrawPolygon(new Pen(brush, thickness), shape); + return source.DrawPolygon(new Pen(brush, thickness), shape); } /// /// Draws the outline of the polygon with the provided brush at the provided thickness. /// /// The type of the color. - /// The type of the packed. /// The source. /// The color. /// The thickness. @@ -105,28 +95,25 @@ namespace ImageSharp /// /// The Image /// - public static Image DrawPolygon(this Image source, TColor color, float thickness, RectangleF shape, GraphicsOptions options) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image DrawPolygon(this Image source, TColor color, float thickness, RectangleF shape, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable { - return source.DrawPolygon(new SolidBrush(color), thickness, shape, options); + return source.DrawPolygon(new SolidBrush(color), thickness, shape, options); } /// /// Draws the outline of the polygon with the provided brush at the provided thickness. /// /// The type of the color. - /// The type of the packed. /// The source. /// The color. /// The thickness. /// The shape. /// The Image - public static Image DrawPolygon(this Image source, TColor color, float thickness, RectangleF shape) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image DrawPolygon(this Image source, TColor color, float thickness, RectangleF shape) + where TColor : struct, IPackedPixel, IEquatable { - return source.DrawPolygon(new SolidBrush(color), thickness, shape); + return source.DrawPolygon(new SolidBrush(color), thickness, shape); } } } diff --git a/src/ImageSharp/Drawing/Fill.cs b/src/ImageSharp/Drawing/Fill.cs index 4a96b20ac..abf4310aa 100644 --- a/src/ImageSharp/Drawing/Fill.cs +++ b/src/ImageSharp/Drawing/Fill.cs @@ -14,7 +14,7 @@ namespace ImageSharp using Drawing.Shapes; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -22,70 +22,61 @@ namespace ImageSharp /// Flood fills the image with the specified brush. /// /// The type of the color. - /// The type of the packed. /// The source. /// The brush. /// The Image - public static Image Fill(this Image source, IBrush brush) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image Fill(this Image source, IBrush brush) + where TColor : struct, IPackedPixel, IEquatable { - return source.Process(new FillProcessor(brush)); + return source.Process(new FillProcessor(brush)); } /// /// Flood fills the image with the specified color. /// /// The type of the color. - /// The type of the packed. /// The source. /// The color. /// The Image - public static Image Fill(this Image source, TColor color) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image Fill(this Image source, TColor color) + where TColor : struct, IPackedPixel, IEquatable { - return source.Fill(new SolidBrush(color)); + return source.Fill(new SolidBrush(color)); } /// /// Flood fills the image in the shape o fhte provided polygon with the specified brush.. /// /// The type of the color. - /// The type of the packed. /// The source. /// The brush. /// The shape. /// The graphics options. /// The Image - public static Image Fill(this Image source, IBrush brush, IShape shape, GraphicsOptions options) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image Fill(this Image source, IBrush brush, IShape shape, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable { - return source.Process(new FillShapeProcessor(brush, shape, options)); + return source.Process(new FillShapeProcessor(brush, shape, options)); } /// - /// Flood fills the image in the shape o fhte 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 type of the packed. /// The source. /// The brush. /// The shape. /// The Image - public static Image Fill(this Image source, IBrush brush, IShape shape) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image Fill(this Image source, IBrush brush, IShape shape) + where TColor : struct, IPackedPixel, IEquatable { - return source.Process(new FillShapeProcessor(brush, shape, GraphicsOptions.Default)); + return source.Process(new FillShapeProcessor(brush, shape, GraphicsOptions.Default)); } /// /// Flood fills the image in the shape o fhte provided polygon with the specified brush.. /// /// The type of the color. - /// The type of the packed. /// The source. /// The color. /// The shape. @@ -93,34 +84,30 @@ namespace ImageSharp /// /// The Image /// - public static Image Fill(this Image source, TColor color, IShape shape, GraphicsOptions options) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image Fill(this Image source, TColor color, IShape shape, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable { - return source.Fill(new SolidBrush(color), shape, options); + return source.Fill(new SolidBrush(color), shape, options); } /// /// Flood fills the image in the shape o fhte provided polygon with the specified brush.. /// /// The type of the color. - /// The type of the packed. /// The source. /// The color. /// The shape. /// The Image - public static Image Fill(this Image source, TColor color, IShape shape) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image Fill(this Image source, TColor color, IShape shape) + where TColor : struct, IPackedPixel, IEquatable { - return source.Fill(new SolidBrush(color), shape); + return source.Fill(new SolidBrush(color), shape); } /// /// Flood fills the image in the shape of a Linear polygon described by the points /// /// The type of the color. - /// The type of the packed. /// The source. /// The brush. /// The points. @@ -128,9 +115,8 @@ namespace ImageSharp /// /// The Image /// - public static Image FillPolygon(this Image source, IBrush brush, Vector2[] points, GraphicsOptions options) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image FillPolygon(this Image source, IBrush brush, Vector2[] points, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable { // using Polygon directly instead of LinearPolygon as its will have less indirection return source.Fill(brush, new Polygon(new LinearLineSegment(points)), options); @@ -140,14 +126,12 @@ namespace ImageSharp /// Flood fills the image in the shape of a Linear polygon described by the points /// /// The type of the color. - /// The type of the packed. /// The source. /// The brush. /// The points. /// The Image - public static Image FillPolygon(this Image source, IBrush brush, Vector2[] points) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image FillPolygon(this Image source, IBrush brush, Vector2[] points) + where TColor : struct, IPackedPixel, IEquatable { // using Polygon directly instead of LinearPolygon as its will have less indirection return source.Fill(brush, new Polygon(new LinearLineSegment(points))); @@ -157,7 +141,6 @@ namespace ImageSharp /// Flood fills the image in the shape of a Linear polygon described by the points /// /// The type of the color. - /// The type of the packed. /// The source. /// The color. /// The points. @@ -165,29 +148,26 @@ namespace ImageSharp /// /// The Image /// - public static Image FillPolygon(this Image source, TColor color, Vector2[] points, GraphicsOptions options) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image FillPolygon(this Image source, TColor color, Vector2[] points, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable { // using Polygon directly instead of LinearPolygon as its will have less indirection - return source.Fill(new SolidBrush(color), new Polygon(new LinearLineSegment(points)), options); + return source.Fill(new SolidBrush(color), new Polygon(new LinearLineSegment(points)), options); } /// /// Flood fills the image in the shape of a Linear polygon described by the points /// /// The type of the color. - /// The type of the packed. /// The source. /// The color. /// The points. /// The Image - public static Image FillPolygon(this Image source, TColor color, Vector2[] points) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image FillPolygon(this Image source, TColor color, Vector2[] points) + where TColor : struct, IPackedPixel, IEquatable { // using Polygon directly instead of LinearPolygon as its will have less indirection - return source.Fill(new SolidBrush(color), new Polygon(new LinearLineSegment(points))); + return source.Fill(new SolidBrush(color), new Polygon(new LinearLineSegment(points))); } } } diff --git a/src/ImageSharp/Drawing/FillRectangle.cs b/src/ImageSharp/Drawing/FillRectangle.cs new file mode 100644 index 000000000..fc29cb4eb --- /dev/null +++ b/src/ImageSharp/Drawing/FillRectangle.cs @@ -0,0 +1,82 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp +{ + using System; + + using Drawing; + using Drawing.Brushes; + using Drawing.Processors; + using Drawing.Shapes; + + /// + /// Extension methods for the type. + /// + public static partial class ImageExtensions + { + /// + /// Flood fills the image in the shape of the provided polygon with the specified brush.. + /// + /// The type of the color. + /// The source. + /// The brush. + /// The shape. + /// The options. + /// + /// The Image + /// + public static Image Fill(this Image source, IBrush brush, RectangleF shape, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Process(new FillShapeProcessor(brush, new RectangularPolygon(shape), options)); + } + + /// + /// Flood fills the image in the shape of the provided polygon with the specified brush.. + /// + /// The type of the color. + /// The source. + /// The brush. + /// The shape. + /// The Image + public static Image Fill(this Image source, IBrush brush, RectangleF shape) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Process(new FillShapeProcessor(brush, new RectangularPolygon(shape), GraphicsOptions.Default)); + } + + /// + /// Flood fills the image in the shape of the provided polygon with the specified brush.. + /// + /// The type of the color. + /// The source. + /// The color. + /// The shape. + /// The options. + /// + /// The Image + /// + public static Image Fill(this Image source, TColor color, RectangleF shape, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Fill(new SolidBrush(color), shape, options); + } + + /// + /// Flood fills the image in the shape of the provided polygon with the specified brush.. + /// + /// The type of the color. + /// The source. + /// The color. + /// The shape. + /// The Image + public static Image Fill(this Image source, TColor color, RectangleF shape) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Fill(new SolidBrush(color), shape); + } + } +} diff --git a/src/ImageSharp/Drawing/Fill_Rectangle.cs b/src/ImageSharp/Drawing/Fill_Rectangle.cs deleted file mode 100644 index f9d075a9f..000000000 --- a/src/ImageSharp/Drawing/Fill_Rectangle.cs +++ /dev/null @@ -1,92 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp -{ - using System; - using System.Numerics; - using Drawing; - using Drawing.Brushes; - using Drawing.Paths; - using Drawing.Processors; - using Drawing.Shapes; - using Processors; - - /// - /// Extension methods for the type. - /// - public static partial class ImageExtensions - { - /// - /// Flood fills the image in the shape o fhte provided polygon with the specified brush.. - /// - /// The type of the color. - /// The type of the packed. - /// The source. - /// The brush. - /// The shape. - /// The options. - /// - /// The Image - /// - public static Image Fill(this Image source, IBrush brush, RectangleF shape, GraphicsOptions options) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable - { - return source.Process(new FillShapeProcessor(brush, new RectangularPolygon(shape), options)); - } - - /// - /// Flood fills the image in the shape o fhte provided polygon with the specified brush.. - /// - /// The type of the color. - /// The type of the packed. - /// The source. - /// The brush. - /// The shape. - /// The Image - public static Image Fill(this Image source, IBrush brush, RectangleF shape) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable - { - return source.Process(new FillShapeProcessor(brush, new RectangularPolygon(shape), GraphicsOptions.Default)); - } - - /// - /// Flood fills the image in the shape o fhte provided polygon with the specified brush.. - /// - /// The type of the color. - /// The type of the packed. - /// The source. - /// The color. - /// The shape. - /// The options. - /// - /// The Image - /// - public static Image Fill(this Image source, TColor color, RectangleF shape, GraphicsOptions options) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable - { - return source.Fill(new SolidBrush(color), shape, options); - } - - /// - /// Flood fills the image in the shape o fhte provided polygon with the specified brush.. - /// - /// The type of the color. - /// The type of the packed. - /// The source. - /// The color. - /// The shape. - /// The Image - public static Image Fill(this Image source, TColor color, RectangleF shape) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable - { - return source.Fill(new SolidBrush(color), shape); - } - } -} diff --git a/src/ImageSharp/Drawing/Pens/IPen.cs b/src/ImageSharp/Drawing/Pens/IPen.cs index 02476976d..0b4d525f2 100644 --- a/src/ImageSharp/Drawing/Pens/IPen.cs +++ b/src/ImageSharp/Drawing/Pens/IPen.cs @@ -9,13 +9,11 @@ namespace ImageSharp.Drawing.Pens using Processors; /// - /// interface preresenting a Pen + /// Interface representing a Pen /// /// The type of the color. - /// The type of the packed. - public interface IPen - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public interface IPen + where TColor : struct, IPackedPixel, IEquatable { /// /// Creates the applicator for applying this pen to an Image @@ -23,9 +21,8 @@ namespace ImageSharp.Drawing.Pens /// The region the pen will be applied to. /// Returns a the applicator for the pen. /// - /// The when being applied to things like shapes would ussually be the - /// bounding box of the shape not necorserrally the shape of the whole image + /// The when being applied to things like shapes would usually be the bounding box of the shape not necessarily the shape of the whole image. /// - IPenApplicator CreateApplicator(RectangleF region); + IPenApplicator CreateApplicator(RectangleF region); } } diff --git a/src/ImageSharp/Drawing/Pens/Pen.cs b/src/ImageSharp/Drawing/Pens/Pen.cs index c4dcaf38c..09fe89419 100644 --- a/src/ImageSharp/Drawing/Pens/Pen.cs +++ b/src/ImageSharp/Drawing/Pens/Pen.cs @@ -5,18 +5,10 @@ namespace ImageSharp.Drawing.Pens { - using System; - using System.Numerics; - - using Brushes; - using Drawing.Processors; - using Paths; - using Processors; - /// - /// Represenets a in the color space. + /// Represents a in the color space. /// - public partial class Pen : Pen + public class Pen : Pen { /// /// Initializes a new instance of the class. @@ -33,7 +25,7 @@ namespace ImageSharp.Drawing.Pens /// /// The brush. /// The width. - public Pen(IBrush brush, float width) + public Pen(IBrush brush, float width) : base(brush, width) { } @@ -44,7 +36,7 @@ namespace ImageSharp.Drawing.Pens /// The brush. /// The width. /// The pattern. - public Pen(IBrush brush, float width, float[] pattern) + public Pen(IBrush brush, float width, float[] pattern) : base(brush, width, pattern) { } @@ -53,263 +45,9 @@ namespace ImageSharp.Drawing.Pens /// Initializes a new instance of the class. /// /// The pen. - internal Pen(Pen pen) + internal Pen(Pen pen) : base(pen) { } } - - /// - /// Provides a pen that can apply a pattern to a line with a set brush and thickness - /// - /// The type of the color. - /// The type of the packed. - /// - /// The pattern will be in to the form of new float[]{ 1f, 2f, 0.5f} this will be - /// converted into a pattern that is 3.5 times longer that the width with 3 sections - /// 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. - /// - public class Pen : IPen - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable - { - private static readonly float[] EmptyPattern = new float[0]; - private readonly float[] pattern; - - /// - /// Initializes a new instance of the class. - /// - /// The color. - /// The width. - /// The pattern. - public Pen(TColor color, float width, float[] pattern) - : this(new SolidBrush(color), width, pattern) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The brush. - /// The width. - /// The pattern. - public Pen(IBrush brush, float width, float[] pattern) - { - this.Brush = brush; - this.Width = width; - this.pattern = pattern; - } - - /// - /// Initializes a new instance of the class. - /// - /// The color. - /// The width. - public Pen(TColor color, float width) - : this(new SolidBrush(color), width) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The brush. - /// The width. - public Pen(IBrush brush, float width) - : this(brush, width, EmptyPattern) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The pen. - internal Pen(Pen pen) - : this(pen.Brush, pen.Width, pen.pattern) - { - } - - /// - /// Gets the brush. - /// - /// - /// The brush. - /// - public IBrush Brush { get; } - - /// - /// Gets the width. - /// - /// - /// The width. - /// - public float Width { get; } - - /// - /// Creates the applicator for applying this pen to an Image - /// - /// The region the pen will be applied to. - /// - /// Returns a the applicator for the pen. - /// - /// - /// The when being applied to things like shapes would ussually be the - /// bounding box of the shape not necorserrally the shape of the whole image - /// - public IPenApplicator CreateApplicator(RectangleF region) - { - if (this.pattern == null || this.pattern.Length < 2) - { - // if there is only one item in the pattern then 100% of it will - // be solid so use the quicker applicator - return new SolidPenApplicator(this.Brush, region, this.Width); - } - - return new PatternPenApplicator(this.Brush, region, this.Width, this.pattern); - } - - private class SolidPenApplicator : IPenApplicator - { - private readonly IBrushApplicator brush; - private readonly float halfWidth; - - public SolidPenApplicator(IBrush brush, RectangleF region, float width) - { - this.brush = brush.CreateApplicator(region); - this.halfWidth = width / 2; - this.RequiredRegion = RectangleF.Outset(region, width); - } - - public RectangleF RequiredRegion - { - get; - } - - public void Dispose() - { - this.brush.Dispose(); - } - - public ColoredPointInfo GetColor(PointInfo info) - { - var result = default(ColoredPointInfo); - result.Color = this.brush.GetColor(info.SearchPoint); - - if (info.DistanceFromPath < this.halfWidth) - { - // inside strip - result.DistanceFromElement = 0; - } - else - { - result.DistanceFromElement = info.DistanceFromPath - this.halfWidth; - } - - return result; - } - } - - private class PatternPenApplicator : IPenApplicator - { - private readonly IBrushApplicator brush; - private readonly float halfWidth; - private readonly float[] pattern; - private readonly float totalLength; - - public PatternPenApplicator(IBrush brush, RectangleF region, float width, float[] pattern) - { - this.brush = brush.CreateApplicator(region); - this.halfWidth = width / 2; - this.totalLength = 0; - - this.pattern = new float[pattern.Length + 1]; - this.pattern[0] = 0; - for (var i = 0; i < pattern.Length; i++) - { - this.totalLength += pattern[i] * width; - this.pattern[i + 1] = this.totalLength; - } - - this.RequiredRegion = RectangleF.Outset(region, width); - } - - public RectangleF RequiredRegion - { - get; - } - - public void Dispose() - { - this.brush.Dispose(); - } - - public ColoredPointInfo GetColor(PointInfo info) - { - var infoResult = default(ColoredPointInfo); - infoResult.DistanceFromElement = float.MaxValue; // is really outside the element - - var length = info.DistanceAlongPath % this.totalLength; - - // we can treat the DistanceAlongPath and DistanceFromPath as x,y coords for the pattern - // we need to calcualte the distance from the outside edge of the pattern - // and set them on the ColoredPointInfo along with the color. - infoResult.Color = this.brush.GetColor(info.SearchPoint); - - float distanceWAway = 0; - - if (info.DistanceFromPath < this.halfWidth) - { - // inside strip - distanceWAway = 0; - } - else - { - distanceWAway = info.DistanceFromPath - this.halfWidth; - } - - for (var i = 0; i < this.pattern.Length - 1; i++) - { - var start = this.pattern[i]; - var end = this.pattern[i + 1]; - - if (length >= start && length < end) - { - // in section - if (i % 2 == 0) - { - // solid part return the maxDistance - infoResult.DistanceFromElement = distanceWAway; - return infoResult; - } - else - { - // this is a none solid part - var distanceFromStart = length - start; - var distanceFromEnd = end - length; - - var closestEdge = Math.Min(distanceFromStart, distanceFromEnd); - - var distanceAcross = closestEdge; - - if (distanceWAway > 0) - { - infoResult.DistanceFromElement = new Vector2(distanceAcross, distanceWAway).Length(); - } - else - { - infoResult.DistanceFromElement = closestEdge; - } - - return infoResult; - } - } - } - - return infoResult; - } - } - } } \ No newline at end of file diff --git a/src/ImageSharp/Drawing/Pens/Pens.cs b/src/ImageSharp/Drawing/Pens/Pens.cs index 4b1b4a2e1..039b7113f 100644 --- a/src/ImageSharp/Drawing/Pens/Pens.cs +++ b/src/ImageSharp/Drawing/Pens/Pens.cs @@ -5,12 +5,10 @@ namespace ImageSharp.Drawing.Pens { - using System; - /// /// Common Pen styles /// - public partial class Pens + public class Pens { /// /// Create a solid pen with out any drawing patterns @@ -18,113 +16,7 @@ namespace ImageSharp.Drawing.Pens /// The color. /// The width. /// The Pen - public static Pen Solid(Color color, float width) - => new Pen(color, width); - - /// - /// Create a solid pen with out any drawing patterns - /// - /// The brush. - /// The width. - /// The Pen - public static Pen Solid(IBrush brush, float width) - => new Pen(brush, width); - - /// - /// Create a pen with a 'Dash' drawing patterns - /// - /// The color. - /// The width. - /// The Pen - public static Pen Dash(Color color, float width) - => new Pen(Pens.Dash(color, width)); - - /// - /// Create a pen with a 'Dash' drawing patterns - /// - /// The brush. - /// The width. - /// The Pen - public static Pen Dash(IBrush brush, float width) - => new Pen(Pens.Dash(brush, width)); - - /// - /// Create a pen with a 'Dot' drawing patterns - /// - /// The color. - /// The width. - /// The Pen - public static Pen Dot(Color color, float width) - => new Pen(Pens.Dot(color, width)); - - /// - /// Create a pen with a 'Dot' drawing patterns - /// - /// The brush. - /// The width. - /// The Pen - public static Pen Dot(IBrush brush, float width) - => new Pen(Pens.Dot(brush, width)); - - /// - /// Create a pen with a 'Dash Dot' drawing patterns - /// - /// The color. - /// The width. - /// The Pen - public static Pen DashDot(Color color, float width) - => new Pen(Pens.DashDot(color, width)); - - /// - /// Create a pen with a 'Dash Dot' drawing patterns - /// - /// The brush. - /// The width. - /// The Pen - public static Pen DashDot(IBrush brush, float width) - => new Pen(Pens.DashDot(brush, width)); - - /// - /// Create a pen with a 'Dash Dot Dot' drawing patterns - /// - /// The color. - /// The width. - /// The Pen - public static Pen DashDotDot(Color color, float width) - => new Pen(Pens.DashDotDot(color, width)); - - /// - /// Create a pen with a 'Dash Dot Dot' drawing patterns - /// - /// The brush. - /// The width. - /// The Pen - public static Pen DashDotDot(IBrush brush, float width) - => new Pen(Pens.DashDotDot(brush, width)); - } - - /// - /// Common Pen styles - /// - /// The type of the color. - /// The type of the packed. - public partial class Pens - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable - { - private static readonly float[] DashDotPattern = new[] { 3f, 1f, 1f, 1f }; - private static readonly float[] DashDotDotPattern = new[] { 3f, 1f, 1f, 1f, 1f, 1f }; - private static readonly float[] DottedPattern = new[] { 1f, 1f }; - private static readonly float[] DashedPattern = new[] { 3f, 1f }; - - /// - /// Create a solid pen with out any drawing patterns - /// - /// The color. - /// The width. - /// The Pen - public static Pen Solid(TColor color, float width) - => new Pen(color, width); + public static Pen Solid(Color color, float width) => new Pen(color, width); /// /// Create a solid pen with out any drawing patterns @@ -132,8 +24,7 @@ namespace ImageSharp.Drawing.Pens /// The brush. /// The width. /// The Pen - public static Pen Solid(IBrush brush, float width) - => new Pen(brush, width); + public static Pen Solid(IBrush brush, float width) => new Pen(brush, width); /// /// Create a pen with a 'Dash' drawing patterns @@ -141,8 +32,7 @@ namespace ImageSharp.Drawing.Pens /// The color. /// The width. /// The Pen - public static Pen Dash(TColor color, float width) - => new Pen(color, width, DashedPattern); + public static Pen Dash(Color color, float width) => new Pen(Pens.Dash(color, width)); /// /// Create a pen with a 'Dash' drawing patterns @@ -150,8 +40,7 @@ namespace ImageSharp.Drawing.Pens /// The brush. /// The width. /// The Pen - public static Pen Dash(IBrush brush, float width) - => new Pen(brush, width, DashedPattern); + public static Pen Dash(IBrush brush, float width) => new Pen(Pens.Dash(brush, width)); /// /// Create a pen with a 'Dot' drawing patterns @@ -159,8 +48,7 @@ namespace ImageSharp.Drawing.Pens /// The color. /// The width. /// The Pen - public static Pen Dot(TColor color, float width) - => new Pen(color, width, DottedPattern); + public static Pen Dot(Color color, float width) => new Pen(Pens.Dot(color, width)); /// /// Create a pen with a 'Dot' drawing patterns @@ -168,8 +56,7 @@ namespace ImageSharp.Drawing.Pens /// The brush. /// The width. /// The Pen - public static Pen Dot(IBrush brush, float width) - => new Pen(brush, width, DottedPattern); + public static Pen Dot(IBrush brush, float width) => new Pen(Pens.Dot(brush, width)); /// /// Create a pen with a 'Dash Dot' drawing patterns @@ -177,8 +64,7 @@ namespace ImageSharp.Drawing.Pens /// The color. /// The width. /// The Pen - public static Pen DashDot(TColor color, float width) - => new Pen(color, width, DashDotPattern); + public static Pen DashDot(Color color, float width) => new Pen(Pens.DashDot(color, width)); /// /// Create a pen with a 'Dash Dot' drawing patterns @@ -186,8 +72,7 @@ namespace ImageSharp.Drawing.Pens /// The brush. /// The width. /// The Pen - public static Pen DashDot(IBrush brush, float width) - => new Pen(brush, width, DashDotPattern); + public static Pen DashDot(IBrush brush, float width) => new Pen(Pens.DashDot(brush, width)); /// /// Create a pen with a 'Dash Dot Dot' drawing patterns @@ -195,8 +80,7 @@ namespace ImageSharp.Drawing.Pens /// The color. /// The width. /// The Pen - public static Pen DashDotDot(TColor color, float width) - => new Pen(color, width, DashDotDotPattern); + public static Pen DashDotDot(Color color, float width) => new Pen(Pens.DashDotDot(color, width)); /// /// Create a pen with a 'Dash Dot Dot' drawing patterns @@ -204,7 +88,6 @@ namespace ImageSharp.Drawing.Pens /// The brush. /// The width. /// The Pen - public static Pen DashDotDot(IBrush brush, float width) - => new Pen(brush, width, DashDotDotPattern); + public static Pen DashDotDot(IBrush brush, float width) => new Pen(Pens.DashDotDot(brush, width)); } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Drawing/Pens/Pens{TColor}.cs b/src/ImageSharp/Drawing/Pens/Pens{TColor}.cs new file mode 100644 index 000000000..94a282659 --- /dev/null +++ b/src/ImageSharp/Drawing/Pens/Pens{TColor}.cs @@ -0,0 +1,112 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Drawing.Pens +{ + using System; + + /// + /// Common Pen styles + /// + /// The type of the color. + public class Pens + where TColor : struct, IPackedPixel, IEquatable + { + private static readonly float[] DashDotPattern = new[] { 3f, 1f, 1f, 1f }; + private static readonly float[] DashDotDotPattern = new[] { 3f, 1f, 1f, 1f, 1f, 1f }; + private static readonly float[] DottedPattern = new[] { 1f, 1f }; + private static readonly float[] DashedPattern = new[] { 3f, 1f }; + + /// + /// Create a solid pen with out any drawing patterns + /// + /// The color. + /// The width. + /// The Pen + public static Pen Solid(TColor color, float width) + => new Pen(color, width); + + /// + /// Create a solid pen with out any drawing patterns + /// + /// The brush. + /// The width. + /// The Pen + public static Pen Solid(IBrush brush, float width) + => new Pen(brush, width); + + /// + /// Create a pen with a 'Dash' drawing patterns + /// + /// The color. + /// The width. + /// The Pen + public static Pen Dash(TColor color, float width) + => new Pen(color, width, DashedPattern); + + /// + /// Create a pen with a 'Dash' drawing patterns + /// + /// The brush. + /// The width. + /// The Pen + public static Pen Dash(IBrush brush, float width) + => new Pen(brush, width, DashedPattern); + + /// + /// Create a pen with a 'Dot' drawing patterns + /// + /// The color. + /// The width. + /// The Pen + public static Pen Dot(TColor color, float width) + => new Pen(color, width, DottedPattern); + + /// + /// Create a pen with a 'Dot' drawing patterns + /// + /// The brush. + /// The width. + /// The Pen + public static Pen Dot(IBrush brush, float width) + => new Pen(brush, width, DottedPattern); + + /// + /// Create a pen with a 'Dash Dot' drawing patterns + /// + /// The color. + /// The width. + /// The Pen + public static Pen DashDot(TColor color, float width) + => new Pen(color, width, DashDotPattern); + + /// + /// Create a pen with a 'Dash Dot' drawing patterns + /// + /// The brush. + /// The width. + /// The Pen + public static Pen DashDot(IBrush brush, float width) + => new Pen(brush, width, DashDotPattern); + + /// + /// Create a pen with a 'Dash Dot Dot' drawing patterns + /// + /// The color. + /// The width. + /// The Pen + public static Pen DashDotDot(TColor color, float width) + => new Pen(color, width, DashDotDotPattern); + + /// + /// Create a pen with a 'Dash Dot Dot' drawing patterns + /// + /// The brush. + /// The width. + /// The Pen + public static Pen DashDotDot(IBrush brush, float width) + => new Pen(brush, width, DashDotDotPattern); + } +} \ No newline at end of file diff --git a/src/ImageSharp/Drawing/Pens/Pen{TColor}.cs b/src/ImageSharp/Drawing/Pens/Pen{TColor}.cs new file mode 100644 index 000000000..e89e7ba82 --- /dev/null +++ b/src/ImageSharp/Drawing/Pens/Pen{TColor}.cs @@ -0,0 +1,267 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Drawing.Pens +{ + using System; + using System.Numerics; + + using ImageSharp.Drawing.Brushes; + using ImageSharp.Drawing.Paths; + using ImageSharp.Drawing.Pens.Processors; + using ImageSharp.Drawing.Processors; + + /// + /// Provides a pen that can apply a pattern to a line with a set brush and thickness + /// + /// The type of the color. + /// + /// The pattern will be in to the form of new float[]{ 1f, 2f, 0.5f} this will be + /// converted into a pattern that is 3.5 times longer that the width with 3 sections + /// 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. + /// + public class Pen : IPen + where TColor : struct, IPackedPixel, IEquatable + { + private static readonly float[] EmptyPattern = new float[0]; + private readonly float[] pattern; + + /// + /// Initializes a new instance of the class. + /// + /// The color. + /// The width. + /// The pattern. + public Pen(TColor color, float width, float[] pattern) + : this(new SolidBrush(color), width, pattern) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The brush. + /// The width. + /// The pattern. + public Pen(IBrush brush, float width, float[] pattern) + { + this.Brush = brush; + this.Width = width; + this.pattern = pattern; + } + + /// + /// Initializes a new instance of the class. + /// + /// The color. + /// The width. + public Pen(TColor color, float width) + : this(new SolidBrush(color), width) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The brush. + /// The width. + public Pen(IBrush brush, float width) + : this(brush, width, EmptyPattern) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The pen. + internal Pen(Pen pen) + : this(pen.Brush, pen.Width, pen.pattern) + { + } + + /// + /// Gets the brush. + /// + /// + /// The brush. + /// + public IBrush Brush { get; } + + /// + /// Gets the width. + /// + /// + /// The width. + /// + public float Width { get; } + + /// + /// Creates the applicator for applying this pen to an Image + /// + /// The region the pen will be applied to. + /// + /// Returns a the applicator for the pen. + /// + /// + /// The when being applied to things like shapes would ussually be the + /// bounding box of the shape not necorserrally the shape of the whole image + /// + public IPenApplicator CreateApplicator(RectangleF region) + { + if (this.pattern == null || this.pattern.Length < 2) + { + // if there is only one item in the pattern then 100% of it will + // be solid so use the quicker applicator + return new SolidPenApplicator(this.Brush, region, this.Width); + } + + return new PatternPenApplicator(this.Brush, region, this.Width, this.pattern); + } + + private class SolidPenApplicator : IPenApplicator + { + private readonly IBrushApplicator brush; + private readonly float halfWidth; + + public SolidPenApplicator(IBrush brush, RectangleF region, float width) + { + this.brush = brush.CreateApplicator(region); + this.halfWidth = width / 2; + this.RequiredRegion = RectangleF.Outset(region, width); + } + + public RectangleF RequiredRegion + { + get; + } + + public void Dispose() + { + this.brush.Dispose(); + } + + public ColoredPointInfo GetColor(PointInfo info) + { + var result = default(ColoredPointInfo); + result.Color = this.brush.GetColor(info.SearchPoint); + + if (info.DistanceFromPath < this.halfWidth) + { + // inside strip + result.DistanceFromElement = 0; + } + else + { + result.DistanceFromElement = info.DistanceFromPath - this.halfWidth; + } + + return result; + } + } + + private class PatternPenApplicator : IPenApplicator + { + private readonly IBrushApplicator brush; + private readonly float halfWidth; + private readonly float[] pattern; + private readonly float totalLength; + + public PatternPenApplicator(IBrush brush, RectangleF region, float width, float[] pattern) + { + this.brush = brush.CreateApplicator(region); + this.halfWidth = width / 2; + this.totalLength = 0; + + this.pattern = new float[pattern.Length + 1]; + this.pattern[0] = 0; + for (var i = 0; i < pattern.Length; i++) + { + this.totalLength += pattern[i] * width; + this.pattern[i + 1] = this.totalLength; + } + + this.RequiredRegion = RectangleF.Outset(region, width); + } + + public RectangleF RequiredRegion + { + get; + } + + public void Dispose() + { + this.brush.Dispose(); + } + + public ColoredPointInfo GetColor(PointInfo info) + { + var infoResult = default(ColoredPointInfo); + infoResult.DistanceFromElement = float.MaxValue; // is really outside the element + + var length = info.DistanceAlongPath % this.totalLength; + + // we can treat the DistanceAlongPath and DistanceFromPath as x,y coords for the pattern + // we need to calcualte the distance from the outside edge of the pattern + // and set them on the ColoredPointInfo along with the color. + infoResult.Color = this.brush.GetColor(info.SearchPoint); + + float distanceWAway = 0; + + if (info.DistanceFromPath < this.halfWidth) + { + // inside strip + distanceWAway = 0; + } + else + { + distanceWAway = info.DistanceFromPath - this.halfWidth; + } + + for (var i = 0; i < this.pattern.Length - 1; i++) + { + var start = this.pattern[i]; + var end = this.pattern[i + 1]; + + if (length >= start && length < end) + { + // in section + if (i % 2 == 0) + { + // solid part return the maxDistance + infoResult.DistanceFromElement = distanceWAway; + return infoResult; + } + else + { + // this is a none solid part + var distanceFromStart = length - start; + var distanceFromEnd = end - length; + + var closestEdge = Math.Min(distanceFromStart, distanceFromEnd); + + var distanceAcross = closestEdge; + + if (distanceWAway > 0) + { + infoResult.DistanceFromElement = new Vector2(distanceAcross, distanceWAway).Length(); + } + else + { + infoResult.DistanceFromElement = closestEdge; + } + + return infoResult; + } + } + } + + return infoResult; + } + } + } +} diff --git a/src/ImageSharp/Drawing/Pens/Processors/ColoredPointInfo.cs b/src/ImageSharp/Drawing/Pens/Processors/ColoredPointInfo.cs index 86f54a143..cb5272425 100644 --- a/src/ImageSharp/Drawing/Pens/Processors/ColoredPointInfo.cs +++ b/src/ImageSharp/Drawing/Pens/Processors/ColoredPointInfo.cs @@ -11,10 +11,8 @@ namespace ImageSharp.Drawing.Pens.Processors /// Returns details about how far away from the inside of a shape and the color the pixel could be. /// /// The type of the color. - /// The type of the packed. - public struct ColoredPointInfo - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public struct ColoredPointInfo + where TColor : struct, IPackedPixel, IEquatable { /// /// The color diff --git a/src/ImageSharp/Drawing/Pens/Processors/IPenApplicator.cs b/src/ImageSharp/Drawing/Pens/Processors/IPenApplicator.cs index f3b244140..c8f381a72 100644 --- a/src/ImageSharp/Drawing/Pens/Processors/IPenApplicator.cs +++ b/src/ImageSharp/Drawing/Pens/Processors/IPenApplicator.cs @@ -12,10 +12,8 @@ namespace ImageSharp.Drawing.Pens.Processors /// primitive that converts a into a color and a distance away from the drawable part of the path. /// /// The type of the color. - /// The type of the packed. - public interface IPenApplicator : IDisposable - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public interface IPenApplicator : IDisposable + where TColor : struct, IPackedPixel, IEquatable { /// /// Gets the required region. @@ -26,10 +24,10 @@ namespace ImageSharp.Drawing.Pens.Processors RectangleF RequiredRegion { get; } /// - /// Gets a from a point represented by a . + /// Gets a from a point represented by a . /// /// The information to extract color details about. /// Returns the color details and distance from a solid bit of the line. - ColoredPointInfo GetColor(PointInfo info); + ColoredPointInfo GetColor(PointInfo info); } } diff --git a/src/ImageSharp/Drawing/Processors/DrawImageProcessor.cs b/src/ImageSharp/Drawing/Processors/DrawImageProcessor.cs index 37921e8d2..05cc7b0dd 100644 --- a/src/ImageSharp/Drawing/Processors/DrawImageProcessor.cs +++ b/src/ImageSharp/Drawing/Processors/DrawImageProcessor.cs @@ -13,19 +13,17 @@ namespace ImageSharp.Processors /// Combines two images together by blending the pixels. /// /// The pixel format. - /// The packed format. uint, long, float. - public class DrawImageProcessor : ImageFilteringProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class DrawImageProcessor : ImageFilteringProcessor + where TColor : struct, IPackedPixel, IEquatable { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The image to blend with the currently processing image. /// The size to draw the blended image. /// The location to draw the blended image. /// The opacity of the image to blend. Between 0 and 100. - public DrawImageProcessor(Image image, Size size, Point location, int alpha = 100) + public DrawImageProcessor(Image image, Size size, Point location, int alpha = 100) { Guard.MustBeBetweenOrEqualTo(alpha, 0, 100, nameof(alpha)); this.Image = image; @@ -37,7 +35,7 @@ namespace ImageSharp.Processors /// /// Gets the image to blend. /// - public Image Image { get; private set; } + public Image Image { get; private set; } /// /// Gets the alpha percentage value. @@ -55,7 +53,7 @@ namespace ImageSharp.Processors public Point Location { get; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { if (this.Image.Bounds.Size != this.Size) { @@ -71,8 +69,8 @@ namespace ImageSharp.Processors float alpha = this.Alpha / 100F; - using (PixelAccessor toBlendPixels = this.Image.Lock()) - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor toBlendPixels = this.Image.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) { Parallel.For( minY, diff --git a/src/ImageSharp/Drawing/Processors/DrawPathProcessor.cs b/src/ImageSharp/Drawing/Processors/DrawPathProcessor.cs index ef04ec0b3..2bb7c350f 100644 --- a/src/ImageSharp/Drawing/Processors/DrawPathProcessor.cs +++ b/src/ImageSharp/Drawing/Processors/DrawPathProcessor.cs @@ -21,50 +21,48 @@ namespace ImageSharp.Drawing.Processors /// Draws a path using the processor pipeline /// /// The type of the color. - /// The type of the packed. - /// - public class DrawPathProcessor : ImageFilteringProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// + public class DrawPathProcessor : ImageFilteringProcessor + where TColor : struct, IPackedPixel, IEquatable { private const float AntialiasFactor = 1f; private const int PaddingFactor = 1; // needs to been the same or greater than AntialiasFactor private const float Epsilon = 0.001f; - private readonly IPen pen; + private readonly IPen pen; private readonly IPath[] paths; private readonly RectangleF region; private readonly GraphicsOptions options; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The pen. /// The shape. /// The options. - public DrawPathProcessor(IPen pen, IShape shape, GraphicsOptions options) + public DrawPathProcessor(IPen pen, IShape shape, GraphicsOptions options) : this(pen, shape.ToArray(), options) { } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The pen. /// The path. /// The options. - public DrawPathProcessor(IPen pen, IPath path, GraphicsOptions options) + public DrawPathProcessor(IPen pen, IPath path, GraphicsOptions options) : this(pen, new[] { path }, options) { } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The pen. /// The paths. /// The options. - public DrawPathProcessor(IPen pen, IPath[] paths, GraphicsOptions options) + public DrawPathProcessor(IPen pen, IPath[] paths, GraphicsOptions options) { this.paths = paths; this.pen = pen; @@ -86,9 +84,9 @@ namespace ImageSharp.Drawing.Processors } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { - using (IPenApplicator applicator = this.pen.CreateApplicator(this.region)) + using (IPenApplicator applicator = this.pen.CreateApplicator(this.region)) { var rect = RectangleF.Ceiling(applicator.RequiredRegion); @@ -119,7 +117,7 @@ namespace ImageSharp.Drawing.Processors polyStartY = 0; } - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) { Parallel.For( minY, diff --git a/src/ImageSharp/Drawing/Processors/FillProcessor.cs b/src/ImageSharp/Drawing/Processors/FillProcessor.cs index 6d2eff972..7e773392b 100644 --- a/src/ImageSharp/Drawing/Processors/FillProcessor.cs +++ b/src/ImageSharp/Drawing/Processors/FillProcessor.cs @@ -16,26 +16,25 @@ namespace ImageSharp.Drawing.Processors /// Using the bursh as a source of pixels colors blends the brush color with source. /// /// The pixel format. - /// The packed format. uint, long, float. - public class FillProcessor : ImageFilteringProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class FillProcessor : ImageFilteringProcessor + where TColor : struct, IPackedPixel, IEquatable { - private const float Epsilon = 0.001f; - - private readonly IBrush brush; + /// + /// The brush. + /// + private readonly IBrush brush; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The brush to source pixel colors from. - public FillProcessor(IBrush brush) + public FillProcessor(IBrush brush) { this.brush = brush; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { int startX = sourceRectangle.X; int endX = sourceRectangle.Right; @@ -60,10 +59,10 @@ namespace ImageSharp.Drawing.Processors } // we could possibly do some optermising by having knowledge about the individual brushes operate - // for example If brush is SolidBrush then we could just get the color upfront - // and skip using the IBrushApplicator?. - using (PixelAccessor sourcePixels = source.Lock()) - using (IBrushApplicator applicator = this.brush.CreateApplicator(sourceRectangle)) + // for example If brush is SolidBrush then we could just get the color upfront + // and skip using the IBrushApplicator?. + using (PixelAccessor sourcePixels = source.Lock()) + using (IBrushApplicator applicator = this.brush.CreateApplicator(sourceRectangle)) { Parallel.For( minY, diff --git a/src/ImageSharp/Drawing/Processors/FillShapeProcessor.cs b/src/ImageSharp/Drawing/Processors/FillShapeProcessor.cs index f44ec56f7..52d3b7a4b 100644 --- a/src/ImageSharp/Drawing/Processors/FillShapeProcessor.cs +++ b/src/ImageSharp/Drawing/Processors/FillShapeProcessor.cs @@ -17,27 +17,25 @@ namespace ImageSharp.Drawing.Processors /// Usinf a brsuh and a shape fills shape with contents of brush the /// /// The type of the color. - /// The type of the packed. - /// - public class FillShapeProcessor : ImageFilteringProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// + public class FillShapeProcessor : ImageFilteringProcessor + where TColor : struct, IPackedPixel, IEquatable { private const float Epsilon = 0.001f; private const float AntialiasFactor = 1f; private const int DrawPadding = 1; - private readonly IBrush fillColor; + private readonly IBrush fillColor; private readonly IShape poly; private readonly GraphicsOptions options; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The brush. /// The shape. /// The graphics options. - public FillShapeProcessor(IBrush brush, IShape shape, GraphicsOptions options) + public FillShapeProcessor(IBrush brush, IShape shape, GraphicsOptions options) { this.poly = shape; this.fillColor = brush; @@ -45,9 +43,9 @@ namespace ImageSharp.Drawing.Processors } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { - var rect = RectangleF.Ceiling(this.poly.Bounds); // rounds the points out away from the center + Rectangle rect = RectangleF.Ceiling(this.poly.Bounds); // rounds the points out away from the center int polyStartY = rect.Y - DrawPadding; int polyEndY = rect.Bottom + DrawPadding; @@ -76,8 +74,8 @@ namespace ImageSharp.Drawing.Processors polyStartY = 0; } - using (PixelAccessor sourcePixels = source.Lock()) - using (IBrushApplicator applicator = this.fillColor.CreateApplicator(rect)) + using (PixelAccessor sourcePixels = source.Lock()) + using (IBrushApplicator applicator = this.fillColor.CreateApplicator(rect)) { Parallel.For( minY, @@ -94,17 +92,15 @@ namespace ImageSharp.Drawing.Processors int offsetX = x - startX; currentPoint.X = offsetX; currentPoint.Y = offsetY; - var dist = this.poly.Distance(currentPoint); - var opacity = this.Opacity(dist); + float dist = this.poly.Distance(currentPoint); + float opacity = this.Opacity(dist); if (opacity > Epsilon) { - int offsetColorX = x - minX; - Vector4 backgroundVector = sourcePixels[offsetX, offsetY].ToVector4(); Vector4 sourceVector = applicator.GetColor(currentPoint).ToVector4(); - var finalColor = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, opacity); + Vector4 finalColor = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, opacity); finalColor.W = backgroundVector.W; TColor packed = default(TColor); @@ -116,13 +112,23 @@ namespace ImageSharp.Drawing.Processors } } + /// + /// Returns the correct alpha value for the given distance. + /// + /// + /// The distance. + /// + /// + /// The . + /// private float Opacity(float distance) { if (distance <= 0) { return 1; } - else if (this.options.Antialias && distance < AntialiasFactor) + + if (this.options.Antialias && distance < AntialiasFactor) { return 1 - (distance / AntialiasFactor); } diff --git a/src/ImageSharp/Filters/Binarization/BinaryThreshold.cs b/src/ImageSharp/Filters/Binarization/BinaryThreshold.cs index e868764c4..ebf28357a 100644 --- a/src/ImageSharp/Filters/Binarization/BinaryThreshold.cs +++ b/src/ImageSharp/Filters/Binarization/BinaryThreshold.cs @@ -10,41 +10,37 @@ namespace ImageSharp using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// - /// Applies binerization to the image splitting the pixels at the given threshold. + /// Applies binarization to the image splitting the pixels at the given threshold. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. - /// The threshold to apply binerization of the image. Must be between 0 and 1. - /// The . - public static Image BinaryThreshold(this Image source, float threshold) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The threshold to apply binarization of the image. Must be between 0 and 1. + /// The . + public static Image BinaryThreshold(this Image source, float threshold) + where TColor : struct, IPackedPixel, IEquatable { return BinaryThreshold(source, threshold, source.Bounds); } /// - /// Applies binerization to the image splitting the pixels at the given threshold. + /// Applies binarization to the image splitting the pixels at the given threshold. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. - /// The threshold to apply binerization of the image. Must be between 0 and 1. + /// The threshold to apply binarization of the image. Must be between 0 and 1. /// /// The structure that specifies the portion of the image object to alter. /// - /// The . - public static Image BinaryThreshold(this Image source, float threshold, Rectangle rectangle) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image BinaryThreshold(this Image source, float threshold, Rectangle rectangle) + where TColor : struct, IPackedPixel, IEquatable { - return source.Process(rectangle, new BinaryThresholdProcessor(threshold)); + return source.Process(rectangle, new BinaryThresholdProcessor(threshold)); } } } diff --git a/src/ImageSharp/Filters/ColorMatrix/BlackWhite.cs b/src/ImageSharp/Filters/ColorMatrix/BlackWhite.cs index 753a1f1a4..a0be4d912 100644 --- a/src/ImageSharp/Filters/ColorMatrix/BlackWhite.cs +++ b/src/ImageSharp/Filters/ColorMatrix/BlackWhite.cs @@ -10,7 +10,7 @@ namespace ImageSharp using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -18,12 +18,10 @@ namespace ImageSharp /// Applies black and white toning to the image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. - /// The . - public static Image BlackWhite(this Image source) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image BlackWhite(this Image source) + where TColor : struct, IPackedPixel, IEquatable { return BlackWhite(source, source.Bounds); } @@ -32,17 +30,15 @@ namespace ImageSharp /// Applies black and white toning to the image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// /// The structure that specifies the portion of the image object to alter. /// - /// The . - public static Image BlackWhite(this Image source, Rectangle rectangle) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image BlackWhite(this Image source, Rectangle rectangle) + where TColor : struct, IPackedPixel, IEquatable { - return source.Process(rectangle, new BlackWhiteProcessor()); + return source.Process(rectangle, new BlackWhiteProcessor()); } } } diff --git a/src/ImageSharp/Filters/ColorMatrix/ColorBlindness.cs b/src/ImageSharp/Filters/ColorMatrix/ColorBlindness.cs index 129de9517..bb30492a7 100644 --- a/src/ImageSharp/Filters/ColorMatrix/ColorBlindness.cs +++ b/src/ImageSharp/Filters/ColorMatrix/ColorBlindness.cs @@ -10,7 +10,7 @@ namespace ImageSharp using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -18,13 +18,11 @@ namespace ImageSharp /// Applies the given colorblindness simulator to the image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The type of color blindness simulator to apply. - /// The . - public static Image ColorBlindness(this Image source, ColorBlindness colorBlindness) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image ColorBlindness(this Image source, ColorBlindness colorBlindness) + where TColor : struct, IPackedPixel, IEquatable { return ColorBlindness(source, colorBlindness, source.Bounds); } @@ -33,51 +31,49 @@ namespace ImageSharp /// Applies the given colorblindness simulator to the image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The type of color blindness simulator to apply. /// /// The structure that specifies the portion of the image object to alter. /// - /// The . - public static Image ColorBlindness(this Image source, ColorBlindness colorBlindness, Rectangle rectangle) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image ColorBlindness(this Image source, ColorBlindness colorBlindness, Rectangle rectangle) + where TColor : struct, IPackedPixel, IEquatable { - IImageFilteringProcessor processor; + IImageFilteringProcessor processor; switch (colorBlindness) { case ImageSharp.ColorBlindness.Achromatomaly: - processor = new AchromatomalyProcessor(); + processor = new AchromatomalyProcessor(); break; case ImageSharp.ColorBlindness.Achromatopsia: - processor = new AchromatopsiaProcessor(); + processor = new AchromatopsiaProcessor(); break; case ImageSharp.ColorBlindness.Deuteranomaly: - processor = new DeuteranomalyProcessor(); + processor = new DeuteranomalyProcessor(); break; case ImageSharp.ColorBlindness.Deuteranopia: - processor = new DeuteranopiaProcessor(); + processor = new DeuteranopiaProcessor(); break; case ImageSharp.ColorBlindness.Protanomaly: - processor = new ProtanomalyProcessor(); + processor = new ProtanomalyProcessor(); break; case ImageSharp.ColorBlindness.Protanopia: - processor = new ProtanopiaProcessor(); + processor = new ProtanopiaProcessor(); break; case ImageSharp.ColorBlindness.Tritanomaly: - processor = new TritanomalyProcessor(); + processor = new TritanomalyProcessor(); break; default: - processor = new TritanopiaProcessor(); + processor = new TritanopiaProcessor(); break; } diff --git a/src/ImageSharp/Filters/ColorMatrix/Grayscale.cs b/src/ImageSharp/Filters/ColorMatrix/Grayscale.cs index 125553827..fa024a852 100644 --- a/src/ImageSharp/Filters/ColorMatrix/Grayscale.cs +++ b/src/ImageSharp/Filters/ColorMatrix/Grayscale.cs @@ -10,7 +10,7 @@ namespace ImageSharp using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -18,13 +18,11 @@ namespace ImageSharp /// Applies Grayscale toning to the image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The formula to apply to perform the operation. - /// The . - public static Image Grayscale(this Image source, GrayscaleMode mode = GrayscaleMode.Bt709) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image Grayscale(this Image source, GrayscaleMode mode = GrayscaleMode.Bt709) + where TColor : struct, IPackedPixel, IEquatable { return Grayscale(source, source.Bounds, mode); } @@ -33,20 +31,18 @@ namespace ImageSharp /// Applies Grayscale toning to the image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// /// The structure that specifies the portion of the image object to alter. /// /// The formula to apply to perform the operation. - /// The . - public static Image Grayscale(this Image source, Rectangle rectangle, GrayscaleMode mode = GrayscaleMode.Bt709) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image Grayscale(this Image source, Rectangle rectangle, GrayscaleMode mode = GrayscaleMode.Bt709) + where TColor : struct, IPackedPixel, IEquatable { - IImageFilteringProcessor processor = mode == GrayscaleMode.Bt709 - ? (IImageFilteringProcessor)new GrayscaleBt709Processor() - : new GrayscaleBt601Processor(); + IImageFilteringProcessor processor = mode == GrayscaleMode.Bt709 + ? (IImageFilteringProcessor)new GrayscaleBt709Processor() + : new GrayscaleBt601Processor(); return source.Process(rectangle, processor); } diff --git a/src/ImageSharp/Filters/ColorMatrix/Hue.cs b/src/ImageSharp/Filters/ColorMatrix/Hue.cs index c91ba4418..52e7d19b8 100644 --- a/src/ImageSharp/Filters/ColorMatrix/Hue.cs +++ b/src/ImageSharp/Filters/ColorMatrix/Hue.cs @@ -10,7 +10,7 @@ namespace ImageSharp using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -18,13 +18,11 @@ namespace ImageSharp /// Alters the hue component of the image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The angle in degrees to adjust the image. - /// The . - public static Image Hue(this Image source, float degrees) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image Hue(this Image source, float degrees) + where TColor : struct, IPackedPixel, IEquatable { return Hue(source, degrees, source.Bounds); } @@ -33,18 +31,16 @@ namespace ImageSharp /// Alters the hue component of the image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The angle in degrees to adjust the image. /// /// The structure that specifies the portion of the image object to alter. /// - /// The . - public static Image Hue(this Image source, float degrees, Rectangle rectangle) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image Hue(this Image source, float degrees, Rectangle rectangle) + where TColor : struct, IPackedPixel, IEquatable { - return source.Process(rectangle, new HueProcessor(degrees)); + return source.Process(rectangle, new HueProcessor(degrees)); } } } diff --git a/src/ImageSharp/Filters/ColorMatrix/Kodachrome.cs b/src/ImageSharp/Filters/ColorMatrix/Kodachrome.cs index 1ba240b46..6f249f3cd 100644 --- a/src/ImageSharp/Filters/ColorMatrix/Kodachrome.cs +++ b/src/ImageSharp/Filters/ColorMatrix/Kodachrome.cs @@ -10,7 +10,7 @@ namespace ImageSharp using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -18,12 +18,10 @@ namespace ImageSharp /// Alters the colors of the image recreating an old Kodachrome camera effect. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. - /// The . - public static Image Kodachrome(this Image source) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image Kodachrome(this Image source) + where TColor : struct, IPackedPixel, IEquatable { return Kodachrome(source, source.Bounds); } @@ -32,17 +30,15 @@ namespace ImageSharp /// Alters the colors of the image recreating an old Kodachrome camera effect. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// /// The structure that specifies the portion of the image object to alter. /// - /// The . - public static Image Kodachrome(this Image source, Rectangle rectangle) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image Kodachrome(this Image source, Rectangle rectangle) + where TColor : struct, IPackedPixel, IEquatable { - return source.Process(rectangle, new KodachromeProcessor()); + return source.Process(rectangle, new KodachromeProcessor()); } } } diff --git a/src/ImageSharp/Filters/ColorMatrix/Lomograph.cs b/src/ImageSharp/Filters/ColorMatrix/Lomograph.cs index 7d4054ccc..06ba76410 100644 --- a/src/ImageSharp/Filters/ColorMatrix/Lomograph.cs +++ b/src/ImageSharp/Filters/ColorMatrix/Lomograph.cs @@ -10,7 +10,7 @@ namespace ImageSharp using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -18,12 +18,10 @@ namespace ImageSharp /// Alters the colors of the image recreating an old Lomograph camera effect. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. - /// The . - public static Image Lomograph(this Image source) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image Lomograph(this Image source) + where TColor : struct, IPackedPixel, IEquatable { return Lomograph(source, source.Bounds); } @@ -32,17 +30,15 @@ namespace ImageSharp /// Alters the colors of the image recreating an old Lomograph camera effect. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// /// The structure that specifies the portion of the image object to alter. /// - /// The . - public static Image Lomograph(this Image source, Rectangle rectangle) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image Lomograph(this Image source, Rectangle rectangle) + where TColor : struct, IPackedPixel, IEquatable { - return source.Process(rectangle, new LomographProcessor()); + return source.Process(rectangle, new LomographProcessor()); } } } diff --git a/src/ImageSharp/Filters/ColorMatrix/Polaroid.cs b/src/ImageSharp/Filters/ColorMatrix/Polaroid.cs index 5605aea17..5df58cea9 100644 --- a/src/ImageSharp/Filters/ColorMatrix/Polaroid.cs +++ b/src/ImageSharp/Filters/ColorMatrix/Polaroid.cs @@ -10,7 +10,7 @@ namespace ImageSharp using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -18,12 +18,10 @@ namespace ImageSharp /// Alters the colors of the image recreating an old Polaroid camera effect. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. - /// The . - public static Image Polaroid(this Image source) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image Polaroid(this Image source) + where TColor : struct, IPackedPixel, IEquatable { return Polaroid(source, source.Bounds); } @@ -32,17 +30,15 @@ namespace ImageSharp /// Alters the colors of the image recreating an old Polaroid camera effect. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// /// The structure that specifies the portion of the image object to alter. /// - /// The . - public static Image Polaroid(this Image source, Rectangle rectangle) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image Polaroid(this Image source, Rectangle rectangle) + where TColor : struct, IPackedPixel, IEquatable { - return source.Process(rectangle, new PolaroidProcessor()); + return source.Process(rectangle, new PolaroidProcessor()); } } } diff --git a/src/ImageSharp/Filters/ColorMatrix/Saturation.cs b/src/ImageSharp/Filters/ColorMatrix/Saturation.cs index a6d89be51..101a45eab 100644 --- a/src/ImageSharp/Filters/ColorMatrix/Saturation.cs +++ b/src/ImageSharp/Filters/ColorMatrix/Saturation.cs @@ -10,7 +10,7 @@ namespace ImageSharp using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -18,13 +18,11 @@ namespace ImageSharp /// Alters the saturation component of the image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The new saturation of the image. Must be between -100 and 100. - /// The . - public static Image Saturation(this Image source, int amount) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image Saturation(this Image source, int amount) + where TColor : struct, IPackedPixel, IEquatable { return Saturation(source, amount, source.Bounds); } @@ -33,18 +31,16 @@ namespace ImageSharp /// Alters the saturation component of the image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The new saturation of the image. Must be between -100 and 100. /// /// The structure that specifies the portion of the image object to alter. /// - /// The . - public static Image Saturation(this Image source, int amount, Rectangle rectangle) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image Saturation(this Image source, int amount, Rectangle rectangle) + where TColor : struct, IPackedPixel, IEquatable { - return source.Process(rectangle, new SaturationProcessor(amount)); + return source.Process(rectangle, new SaturationProcessor(amount)); } } } diff --git a/src/ImageSharp/Filters/ColorMatrix/Sepia.cs b/src/ImageSharp/Filters/ColorMatrix/Sepia.cs index c7215390f..a3641bfe3 100644 --- a/src/ImageSharp/Filters/ColorMatrix/Sepia.cs +++ b/src/ImageSharp/Filters/ColorMatrix/Sepia.cs @@ -10,7 +10,7 @@ namespace ImageSharp using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -18,12 +18,10 @@ namespace ImageSharp /// Applies sepia toning to the image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The . - public static Image Sepia(this Image source) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image Sepia(this Image source) + where TColor : struct, IPackedPixel, IEquatable { return Sepia(source, source.Bounds); } @@ -32,17 +30,15 @@ namespace ImageSharp /// Applies sepia toning to the image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Sepia(this Image source, Rectangle rectangle) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image Sepia(this Image source, Rectangle rectangle) + where TColor : struct, IPackedPixel, IEquatable { - return source.Process(rectangle, new SepiaProcessor()); + return source.Process(rectangle, new SepiaProcessor()); } } } \ No newline at end of file diff --git a/src/ImageSharp/Filters/Convolution/BoxBlur.cs b/src/ImageSharp/Filters/Convolution/BoxBlur.cs index cdc92e1cf..e07da5b30 100644 --- a/src/ImageSharp/Filters/Convolution/BoxBlur.cs +++ b/src/ImageSharp/Filters/Convolution/BoxBlur.cs @@ -10,7 +10,7 @@ namespace ImageSharp using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -18,13 +18,11 @@ namespace ImageSharp /// Applies a box blur to the image. /// /// The pixel format. - /// The packed format. long, float. /// The image this method extends. /// The 'radius' value representing the size of the area to sample. - /// The . - public static Image BoxBlur(this Image source, int radius = 7) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image BoxBlur(this Image source, int radius = 7) + where TColor : struct, IPackedPixel, IEquatable { return BoxBlur(source, radius, source.Bounds); } @@ -33,18 +31,16 @@ namespace ImageSharp /// Applies a box blur to the image. /// /// The pixel format. - /// The packed format. long, float. /// The image this method extends. /// The 'radius' value representing the size of the area to sample. /// /// The structure that specifies the portion of the image object to alter. /// - /// The . - public static Image BoxBlur(this Image source, int radius, Rectangle rectangle) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image BoxBlur(this Image source, int radius, Rectangle rectangle) + where TColor : struct, IPackedPixel, IEquatable { - return source.Process(rectangle, new BoxBlurProcessor(radius)); + return source.Process(rectangle, new BoxBlurProcessor(radius)); } } } diff --git a/src/ImageSharp/Filters/Convolution/DetectEdges.cs b/src/ImageSharp/Filters/Convolution/DetectEdges.cs index 86c850360..fe5cf01a2 100644 --- a/src/ImageSharp/Filters/Convolution/DetectEdges.cs +++ b/src/ImageSharp/Filters/Convolution/DetectEdges.cs @@ -10,55 +10,49 @@ namespace ImageSharp using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// - /// Detects any edges within the image. Uses the filter + /// Detects any edges within the image. Uses the filter /// operating in Grayscale mode. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. - /// The . - public static Image DetectEdges(this Image source) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image DetectEdges(this Image source) + where TColor : struct, IPackedPixel, IEquatable { - return DetectEdges(source, source.Bounds, new SobelProcessor { Grayscale = true }); + return DetectEdges(source, source.Bounds, new SobelProcessor { Grayscale = true }); } /// - /// Detects any edges within the image. Uses the filter + /// Detects any edges within the image. Uses the filter /// operating in Grayscale mode. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// /// The structure that specifies the portion of the image object to alter. /// - /// The . - public static Image DetectEdges(this Image source, Rectangle rectangle) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image DetectEdges(this Image source, Rectangle rectangle) + where TColor : struct, IPackedPixel, IEquatable { - return DetectEdges(source, rectangle, new SobelProcessor { Grayscale = true }); + return DetectEdges(source, rectangle, new SobelProcessor { Grayscale = true }); } /// /// Detects any edges within the image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The filter for detecting edges. /// Whether to convert the image to Grayscale first. Defaults to true. - /// The . - public static Image DetectEdges(this Image source, EdgeDetection filter, bool grayscale = true) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image DetectEdges(this Image source, EdgeDetection filter, bool grayscale = true) + where TColor : struct, IPackedPixel, IEquatable { return DetectEdges(source, filter, source.Bounds, grayscale); } @@ -67,60 +61,58 @@ namespace ImageSharp /// Detects any edges within the image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The filter for detecting edges. /// /// The structure that specifies the portion of the image object to alter. /// /// Whether to convert the image to Grayscale first. Defaults to true. - /// The . - public static Image DetectEdges(this Image source, EdgeDetection filter, Rectangle rectangle, bool grayscale = true) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image DetectEdges(this Image source, EdgeDetection filter, Rectangle rectangle, bool grayscale = true) + where TColor : struct, IPackedPixel, IEquatable { - IEdgeDetectorProcessor processor; + IEdgeDetectorProcessor processor; switch (filter) { case EdgeDetection.Kayyali: - processor = new KayyaliProcessor { Grayscale = grayscale }; + processor = new KayyaliProcessor { Grayscale = grayscale }; break; case EdgeDetection.Kirsch: - processor = new KirschProcessor { Grayscale = grayscale }; + processor = new KirschProcessor { Grayscale = grayscale }; break; case EdgeDetection.Lapacian3X3: - processor = new Laplacian3X3Processor { Grayscale = grayscale }; + processor = new Laplacian3X3Processor { Grayscale = grayscale }; break; case EdgeDetection.Lapacian5X5: - processor = new Laplacian5X5Processor { Grayscale = grayscale }; + processor = new Laplacian5X5Processor { Grayscale = grayscale }; break; case EdgeDetection.LaplacianOfGaussian: - processor = new LaplacianOfGaussianProcessor { Grayscale = grayscale }; + processor = new LaplacianOfGaussianProcessor { Grayscale = grayscale }; break; case EdgeDetection.Prewitt: - processor = new PrewittProcessor { Grayscale = grayscale }; + processor = new PrewittProcessor { Grayscale = grayscale }; break; case EdgeDetection.RobertsCross: - processor = new RobertsCrossProcessor { Grayscale = grayscale }; + processor = new RobertsCrossProcessor { Grayscale = grayscale }; break; case EdgeDetection.Robinson: - processor = new RobinsonProcessor { Grayscale = grayscale }; + processor = new RobinsonProcessor { Grayscale = grayscale }; break; case EdgeDetection.Scharr: - processor = new ScharrProcessor { Grayscale = grayscale }; + processor = new ScharrProcessor { Grayscale = grayscale }; break; default: - processor = new SobelProcessor { Grayscale = grayscale }; + processor = new SobelProcessor { Grayscale = grayscale }; break; } @@ -131,13 +123,11 @@ namespace ImageSharp /// Detects any edges within the image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The filter for detecting edges. - /// The . - public static Image DetectEdges(this Image source, IEdgeDetectorProcessor filter) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image DetectEdges(this Image source, IEdgeDetectorProcessor filter) + where TColor : struct, IPackedPixel, IEquatable { return DetectEdges(source, source.Bounds, filter); } @@ -146,16 +136,14 @@ namespace ImageSharp /// Detects any edges within the image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// /// The structure that specifies the portion of the image object to alter. /// /// The filter for detecting edges. - /// The . - public static Image DetectEdges(this Image source, Rectangle rectangle, IEdgeDetectorProcessor filter) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image DetectEdges(this Image source, Rectangle rectangle, IEdgeDetectorProcessor filter) + where TColor : struct, IPackedPixel, IEquatable { return source.Process(rectangle, filter); } diff --git a/src/ImageSharp/Filters/Convolution/GaussianBlur.cs b/src/ImageSharp/Filters/Convolution/GaussianBlur.cs index e1e7a74ea..0f03864b5 100644 --- a/src/ImageSharp/Filters/Convolution/GaussianBlur.cs +++ b/src/ImageSharp/Filters/Convolution/GaussianBlur.cs @@ -10,7 +10,7 @@ namespace ImageSharp using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -18,13 +18,11 @@ namespace ImageSharp /// Applies a Gaussian blur to the image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The 'sigma' value representing the weight of the blur. - /// The . - public static Image GaussianBlur(this Image source, float sigma = 3f) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image GaussianBlur(this Image source, float sigma = 3f) + where TColor : struct, IPackedPixel, IEquatable { return GaussianBlur(source, sigma, source.Bounds); } @@ -33,18 +31,16 @@ namespace ImageSharp /// Applies a Gaussian blur to the image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The 'sigma' value representing the weight of the blur. /// /// The structure that specifies the portion of the image object to alter. /// - /// The . - public static Image GaussianBlur(this Image source, float sigma, Rectangle rectangle) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image GaussianBlur(this Image source, float sigma, Rectangle rectangle) + where TColor : struct, IPackedPixel, IEquatable { - return source.Process(rectangle, new GaussianBlurProcessor(sigma)); + return source.Process(rectangle, new GaussianBlurProcessor(sigma)); } } } \ No newline at end of file diff --git a/src/ImageSharp/Filters/Convolution/GaussianSharpen.cs b/src/ImageSharp/Filters/Convolution/GaussianSharpen.cs index 57e5174ef..39beddf46 100644 --- a/src/ImageSharp/Filters/Convolution/GaussianSharpen.cs +++ b/src/ImageSharp/Filters/Convolution/GaussianSharpen.cs @@ -10,7 +10,7 @@ namespace ImageSharp using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -18,13 +18,11 @@ namespace ImageSharp /// Applies a Gaussian sharpening filter to the image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The 'sigma' value representing the weight of the blur. - /// The . - public static Image GaussianSharpen(this Image source, float sigma = 3f) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image GaussianSharpen(this Image source, float sigma = 3f) + where TColor : struct, IPackedPixel, IEquatable { return GaussianSharpen(source, sigma, source.Bounds); } @@ -33,18 +31,16 @@ namespace ImageSharp /// Applies a Gaussian sharpening filter to the image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The 'sigma' value representing the weight of the blur. /// /// The structure that specifies the portion of the image object to alter. /// - /// The . - public static Image GaussianSharpen(this Image source, float sigma, Rectangle rectangle) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image GaussianSharpen(this Image source, float sigma, Rectangle rectangle) + where TColor : struct, IPackedPixel, IEquatable { - return source.Process(rectangle, new GaussianSharpenProcessor(sigma)); + return source.Process(rectangle, new GaussianSharpenProcessor(sigma)); } } } diff --git a/src/ImageSharp/Filters/Effects/Alpha.cs b/src/ImageSharp/Filters/Effects/Alpha.cs index c45deb176..8c765472d 100644 --- a/src/ImageSharp/Filters/Effects/Alpha.cs +++ b/src/ImageSharp/Filters/Effects/Alpha.cs @@ -18,13 +18,11 @@ namespace ImageSharp /// Alters the alpha component of the image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The new opacity of the image. Must be between 0 and 100. - /// The . - public static Image Alpha(this Image source, int percent) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image Alpha(this Image source, int percent) + where TColor : struct, IPackedPixel, IEquatable { return Alpha(source, percent, source.Bounds); } @@ -33,18 +31,16 @@ namespace ImageSharp /// Alters the alpha component of the image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The new opacity of the image. Must be between 0 and 100. /// /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Alpha(this Image source, int percent, Rectangle rectangle) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image Alpha(this Image source, int percent, Rectangle rectangle) + where TColor : struct, IPackedPixel, IEquatable { - return source.Process(rectangle, new AlphaProcessor(percent)); + return source.Process(rectangle, new AlphaProcessor(percent)); } } } diff --git a/src/ImageSharp/Filters/Effects/BackgroundColor.cs b/src/ImageSharp/Filters/Effects/BackgroundColor.cs index fe5884acf..d7971ba9c 100644 --- a/src/ImageSharp/Filters/Effects/BackgroundColor.cs +++ b/src/ImageSharp/Filters/Effects/BackgroundColor.cs @@ -10,7 +10,7 @@ namespace ImageSharp using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -18,15 +18,13 @@ namespace ImageSharp /// Replaces the background color of image with the given one. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The color to set as the background. - /// The . - public static Image BackgroundColor(this Image source, TColor color) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image BackgroundColor(this Image source, TColor color) + where TColor : struct, IPackedPixel, IEquatable { - return source.Process(source.Bounds, new BackgroundColorProcessor(color)); + return source.Process(source.Bounds, new BackgroundColorProcessor(color)); } } } diff --git a/src/ImageSharp/Filters/Effects/Brightness.cs b/src/ImageSharp/Filters/Effects/Brightness.cs index 2d2a42247..6f051605d 100644 --- a/src/ImageSharp/Filters/Effects/Brightness.cs +++ b/src/ImageSharp/Filters/Effects/Brightness.cs @@ -10,7 +10,7 @@ namespace ImageSharp using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -18,14 +18,12 @@ namespace ImageSharp /// Alters the brightness component of the image. /// /// The pixel format. - /// The packed format. uint, long, float. - /// The image this method extends. + /// The image this method extends. /// The new brightness of the image. Must be between -100 and 100. - /// The . - public static Image Brightness(this Image source, int amount) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable - { + /// The . + public static Image Brightness(this Image source, int amount) + where TColor : struct, IPackedPixel, IEquatable + { return Brightness(source, amount, source.Bounds); } @@ -33,18 +31,16 @@ namespace ImageSharp /// Alters the brightness component of the image. /// /// The pixel format. - /// The packed format. uint, long, float. - /// The image this method extends. + /// The image this method extends. /// The new brightness of the image. Must be between -100 and 100. /// /// The structure that specifies the portion of the image object to alter. /// - /// The . - public static Image Brightness(this Image source, int amount, Rectangle rectangle) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable - { - return source.Process(rectangle, new BrightnessProcessor(amount)); + /// The . + public static Image Brightness(this Image source, int amount, Rectangle rectangle) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Process(rectangle, new BrightnessProcessor(amount)); } } } diff --git a/src/ImageSharp/Filters/Effects/Contrast.cs b/src/ImageSharp/Filters/Effects/Contrast.cs index 279e874f1..338ae1d1f 100644 --- a/src/ImageSharp/Filters/Effects/Contrast.cs +++ b/src/ImageSharp/Filters/Effects/Contrast.cs @@ -10,7 +10,7 @@ namespace ImageSharp using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -18,13 +18,11 @@ namespace ImageSharp /// Alters the contrast component of the image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The new contrast of the image. Must be between -100 and 100. - /// The . - public static Image Contrast(this Image source, int amount) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image Contrast(this Image source, int amount) + where TColor : struct, IPackedPixel, IEquatable { return Contrast(source, amount, source.Bounds); } @@ -33,18 +31,16 @@ namespace ImageSharp /// Alters the contrast component of the image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The new contrast of the image. Must be between -100 and 100. /// /// The structure that specifies the portion of the image object to alter. /// - /// The . - public static Image Contrast(this Image source, int amount, Rectangle rectangle) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image Contrast(this Image source, int amount, Rectangle rectangle) + where TColor : struct, IPackedPixel, IEquatable { - return source.Process(rectangle, new ContrastProcessor(amount)); + return source.Process(rectangle, new ContrastProcessor(amount)); } } } diff --git a/src/ImageSharp/Filters/Effects/Invert.cs b/src/ImageSharp/Filters/Effects/Invert.cs index 148e9c7d8..95a58835c 100644 --- a/src/ImageSharp/Filters/Effects/Invert.cs +++ b/src/ImageSharp/Filters/Effects/Invert.cs @@ -10,7 +10,7 @@ namespace ImageSharp using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -18,12 +18,10 @@ namespace ImageSharp /// Inverts the colors of the image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The . - public static Image Invert(this Image source) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image Invert(this Image source) + where TColor : struct, IPackedPixel, IEquatable { return Invert(source, source.Bounds); } @@ -32,17 +30,15 @@ namespace ImageSharp /// Inverts the colors of the image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Invert(this Image source, Rectangle rectangle) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image Invert(this Image source, Rectangle rectangle) + where TColor : struct, IPackedPixel, IEquatable { - return source.Process(rectangle, new InvertProcessor()); + return source.Process(rectangle, new InvertProcessor()); } } } diff --git a/src/ImageSharp/Filters/Effects/OilPainting.cs b/src/ImageSharp/Filters/Effects/OilPainting.cs index e31f51178..59195c400 100644 --- a/src/ImageSharp/Filters/Effects/OilPainting.cs +++ b/src/ImageSharp/Filters/Effects/OilPainting.cs @@ -10,7 +10,7 @@ namespace ImageSharp using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -18,14 +18,12 @@ namespace ImageSharp /// Alters the colors of the image recreating an oil painting effect. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The number of intensity levels. Higher values result in a broader range of color intensities forming part of the result image. /// The number of neighboring pixels used in calculating each individual pixel value. - /// The . - public static Image OilPaint(this Image source, int levels = 10, int brushSize = 15) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image OilPaint(this Image source, int levels = 10, int brushSize = 15) + where TColor : struct, IPackedPixel, IEquatable { return OilPaint(source, levels, brushSize, source.Bounds); } @@ -34,17 +32,15 @@ namespace ImageSharp /// Alters the colors of the image recreating an oil painting effect. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The number of intensity levels. Higher values result in a broader range of color intensities forming part of the result image. /// The number of neighboring pixels used in calculating each individual pixel value. /// /// The structure that specifies the portion of the image object to alter. /// - /// The . - public static Image OilPaint(this Image source, int levels, int brushSize, Rectangle rectangle) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image OilPaint(this Image source, int levels, int brushSize, Rectangle rectangle) + where TColor : struct, IPackedPixel, IEquatable { Guard.MustBeGreaterThan(levels, 0, nameof(levels)); @@ -53,7 +49,7 @@ namespace ImageSharp throw new ArgumentOutOfRangeException(nameof(brushSize)); } - return source.Process(rectangle, new OilPaintingProcessor(levels, brushSize)); + return source.Process(rectangle, new OilPaintingProcessor(levels, brushSize)); } } } \ No newline at end of file diff --git a/src/ImageSharp/Filters/Effects/Pixelate.cs b/src/ImageSharp/Filters/Effects/Pixelate.cs index a221d7fc0..6fada475b 100644 --- a/src/ImageSharp/Filters/Effects/Pixelate.cs +++ b/src/ImageSharp/Filters/Effects/Pixelate.cs @@ -10,7 +10,7 @@ namespace ImageSharp using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -18,13 +18,11 @@ namespace ImageSharp /// Pixelates an image with the given pixel size. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The size of the pixels. - /// The . - public static Image Pixelate(this Image source, int size = 4) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image Pixelate(this Image source, int size = 4) + where TColor : struct, IPackedPixel, IEquatable { return Pixelate(source, size, source.Bounds); } @@ -33,23 +31,21 @@ namespace ImageSharp /// Pixelates an image with the given pixel size. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The size of the pixels. /// /// The structure that specifies the portion of the image object to alter. /// - /// The . - public static Image Pixelate(this Image source, int size, Rectangle rectangle) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image Pixelate(this Image source, int size, Rectangle rectangle) + where TColor : struct, IPackedPixel, IEquatable { if (size <= 0 || size > source.Height || size > source.Width) { throw new ArgumentOutOfRangeException(nameof(size)); } - return source.Process(rectangle, new PixelateProcessor(size)); + return source.Process(rectangle, new PixelateProcessor(size)); } } } \ No newline at end of file diff --git a/src/ImageSharp/Filters/Overlays/Glow.cs b/src/ImageSharp/Filters/Overlays/Glow.cs index ed2d8ffbb..4f5a05852 100644 --- a/src/ImageSharp/Filters/Overlays/Glow.cs +++ b/src/ImageSharp/Filters/Overlays/Glow.cs @@ -10,7 +10,7 @@ namespace ImageSharp using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -18,12 +18,10 @@ namespace ImageSharp /// Applies a radial glow effect to an image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. - /// The . - public static Image Glow(this Image source) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image Glow(this Image source) + where TColor : struct, IPackedPixel, IEquatable { return Glow(source, default(TColor), source.Bounds.Width * .5F, source.Bounds); } @@ -32,13 +30,11 @@ namespace ImageSharp /// Applies a radial glow effect to an image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The color to set as the glow. - /// The . - public static Image Glow(this Image source, TColor color) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image Glow(this Image source, TColor color) + where TColor : struct, IPackedPixel, IEquatable { return Glow(source, color, source.Bounds.Width * .5F, source.Bounds); } @@ -47,13 +43,11 @@ namespace ImageSharp /// Applies a radial glow effect to an image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The the radius. - /// The . - public static Image Glow(this Image source, float radius) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image Glow(this Image source, float radius) + where TColor : struct, IPackedPixel, IEquatable { return Glow(source, default(TColor), radius, source.Bounds); } @@ -62,15 +56,13 @@ namespace ImageSharp /// Applies a radial glow effect to an image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// /// The structure that specifies the portion of the image object to alter. /// - /// The . - public static Image Glow(this Image source, Rectangle rectangle) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image Glow(this Image source, Rectangle rectangle) + where TColor : struct, IPackedPixel, IEquatable { return Glow(source, default(TColor), 0, rectangle); } @@ -79,19 +71,17 @@ namespace ImageSharp /// Applies a radial glow effect to an image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The color to set as the glow. /// The the radius. /// /// The structure that specifies the portion of the image object to alter. /// - /// The . - public static Image Glow(this Image source, TColor color, float radius, Rectangle rectangle) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image Glow(this Image source, TColor color, float radius, Rectangle rectangle) + where TColor : struct, IPackedPixel, IEquatable { - GlowProcessor processor = new GlowProcessor { Radius = radius, }; + GlowProcessor processor = new GlowProcessor { Radius = radius, }; if (!color.Equals(default(TColor))) { diff --git a/src/ImageSharp/Filters/Overlays/Vignette.cs b/src/ImageSharp/Filters/Overlays/Vignette.cs index 31fe1c5b6..7f5ade12d 100644 --- a/src/ImageSharp/Filters/Overlays/Vignette.cs +++ b/src/ImageSharp/Filters/Overlays/Vignette.cs @@ -10,7 +10,7 @@ namespace ImageSharp using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -18,12 +18,10 @@ namespace ImageSharp /// Applies a radial vignette effect to an image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. - /// The . - public static Image Vignette(this Image source) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image Vignette(this Image source) + where TColor : struct, IPackedPixel, IEquatable { return Vignette(source, default(TColor), source.Bounds.Width * .5F, source.Bounds.Height * .5F, source.Bounds); } @@ -32,13 +30,11 @@ namespace ImageSharp /// Applies a radial vignette effect to an image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The color to set as the vignette. - /// The . - public static Image Vignette(this Image source, TColor color) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image Vignette(this Image source, TColor color) + where TColor : struct, IPackedPixel, IEquatable { return Vignette(source, color, source.Bounds.Width * .5F, source.Bounds.Height * .5F, source.Bounds); } @@ -47,14 +43,12 @@ namespace ImageSharp /// Applies a radial vignette effect to an image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The the x-radius. /// The the y-radius. - /// The . - public static Image Vignette(this Image source, float radiusX, float radiusY) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image Vignette(this Image source, float radiusX, float radiusY) + where TColor : struct, IPackedPixel, IEquatable { return Vignette(source, default(TColor), radiusX, radiusY, source.Bounds); } @@ -63,15 +57,13 @@ namespace ImageSharp /// Applies a radial vignette effect to an image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// /// The structure that specifies the portion of the image object to alter. /// - /// The . - public static Image Vignette(this Image source, Rectangle rectangle) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image Vignette(this Image source, Rectangle rectangle) + where TColor : struct, IPackedPixel, IEquatable { return Vignette(source, default(TColor), 0, 0, rectangle); } @@ -80,7 +72,6 @@ namespace ImageSharp /// Applies a radial vignette effect to an image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The color to set as the vignette. /// The the x-radius. @@ -88,12 +79,11 @@ namespace ImageSharp /// /// The structure that specifies the portion of the image object to alter. /// - /// The . - public static Image Vignette(this Image source, TColor color, float radiusX, float radiusY, Rectangle rectangle) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image Vignette(this Image source, TColor color, float radiusX, float radiusY, Rectangle rectangle) + where TColor : struct, IPackedPixel, IEquatable { - VignetteProcessor processor = new VignetteProcessor { RadiusX = radiusX, RadiusY = radiusY }; + VignetteProcessor processor = new VignetteProcessor { RadiusX = radiusX, RadiusY = radiusY }; if (!color.Equals(default(TColor))) { diff --git a/src/ImageSharp/Filters/Processors/Binarization/BinaryThresholdProcessor.cs b/src/ImageSharp/Filters/Processors/Binarization/BinaryThresholdProcessor.cs index 84b88222b..baf9c36ca 100644 --- a/src/ImageSharp/Filters/Processors/Binarization/BinaryThresholdProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Binarization/BinaryThresholdProcessor.cs @@ -9,17 +9,15 @@ namespace ImageSharp.Processors using System.Threading.Tasks; /// - /// An to perform binary threshold filtering against an + /// An to perform binary threshold filtering against an /// . The image will be converted to grayscale before thresholding occurs. /// /// The pixel format. - /// The packed format. uint, long, float. - public class BinaryThresholdProcessor : ImageFilteringProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class BinaryThresholdProcessor : ImageFilteringProcessor + where TColor : struct, IPackedPixel, IEquatable { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The threshold to split the image. Must be between 0 and 1. /// @@ -56,13 +54,13 @@ namespace ImageSharp.Processors public TColor LowerColor { get; set; } /// - protected override void BeforeApply(ImageBase source, Rectangle sourceRectangle) + protected override void BeforeApply(ImageBase source, Rectangle sourceRectangle) { - new GrayscaleBt709Processor().Apply(source, sourceRectangle); + new GrayscaleBt709Processor().Apply(source, sourceRectangle); } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { float threshold = this.Value; TColor upper = this.UpperColor; @@ -90,7 +88,7 @@ namespace ImageSharp.Processors startY = 0; } - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) { Parallel.For( minY, diff --git a/src/ImageSharp/Filters/Processors/ColorMatrix/BlackWhiteProcessor.cs b/src/ImageSharp/Filters/Processors/ColorMatrix/BlackWhiteProcessor.cs index f59cd34e7..942be785c 100644 --- a/src/ImageSharp/Filters/Processors/ColorMatrix/BlackWhiteProcessor.cs +++ b/src/ImageSharp/Filters/Processors/ColorMatrix/BlackWhiteProcessor.cs @@ -12,10 +12,8 @@ namespace ImageSharp.Processors /// Converts the colors of the image to their black and white equivalent. /// /// The pixel format. - /// The packed format. uint, long, float. - public class BlackWhiteProcessor : ColorMatrixFilter - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class BlackWhiteProcessor : ColorMatrixFilter + where TColor : struct, IPackedPixel, IEquatable { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/AchromatomalyProcessor.cs b/src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/AchromatomalyProcessor.cs index 6d15e094d..2b8ca8857 100644 --- a/src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/AchromatomalyProcessor.cs +++ b/src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/AchromatomalyProcessor.cs @@ -12,10 +12,8 @@ namespace ImageSharp.Processors /// Converts the colors of the image recreating Achromatomaly (Color desensitivity) color blindness. /// /// The pixel format. - /// The packed format. uint, long, float. - public class AchromatomalyProcessor : ColorMatrixFilter - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class AchromatomalyProcessor : ColorMatrixFilter + where TColor : struct, IPackedPixel, IEquatable { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/AchromatopsiaProcessor.cs b/src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/AchromatopsiaProcessor.cs index 96dc756de..d9530ad26 100644 --- a/src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/AchromatopsiaProcessor.cs +++ b/src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/AchromatopsiaProcessor.cs @@ -12,10 +12,8 @@ namespace ImageSharp.Processors /// Converts the colors of the image recreating Achromatopsia (Monochrome) color blindness. /// /// The pixel format. - /// The packed format. uint, long, float. - public class AchromatopsiaProcessor : ColorMatrixFilter - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class AchromatopsiaProcessor : ColorMatrixFilter + where TColor : struct, IPackedPixel, IEquatable { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/DeuteranomalyProcessor.cs b/src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/DeuteranomalyProcessor.cs index 7445460f8..84e185b40 100644 --- a/src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/DeuteranomalyProcessor.cs +++ b/src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/DeuteranomalyProcessor.cs @@ -12,10 +12,8 @@ namespace ImageSharp.Processors /// Converts the colors of the image recreating Deuteranomaly (Green-Weak) color blindness. /// /// The pixel format. - /// The packed format. uint, long, float. - public class DeuteranomalyProcessor : ColorMatrixFilter - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class DeuteranomalyProcessor : ColorMatrixFilter + where TColor : struct, IPackedPixel, IEquatable { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/DeuteranopiaProcessor.cs b/src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/DeuteranopiaProcessor.cs index 95e301954..026fd2832 100644 --- a/src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/DeuteranopiaProcessor.cs +++ b/src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/DeuteranopiaProcessor.cs @@ -12,10 +12,8 @@ namespace ImageSharp.Processors /// Converts the colors of the image recreating Deuteranopia (Green-Blind) color blindness. /// /// The pixel format. - /// The packed format. uint, long, float. - public class DeuteranopiaProcessor : ColorMatrixFilter - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class DeuteranopiaProcessor : ColorMatrixFilter + where TColor : struct, IPackedPixel, IEquatable { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/ProtanomalyProcessor.cs b/src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/ProtanomalyProcessor.cs index 7d6ad7397..92f4fc1f8 100644 --- a/src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/ProtanomalyProcessor.cs +++ b/src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/ProtanomalyProcessor.cs @@ -12,10 +12,8 @@ namespace ImageSharp.Processors /// Converts the colors of the image recreating Protanopia (Red-Weak) color blindness. /// /// The pixel format. - /// The packed format. uint, long, float. - public class ProtanomalyProcessor : ColorMatrixFilter - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class ProtanomalyProcessor : ColorMatrixFilter + where TColor : struct, IPackedPixel, IEquatable { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/ProtanopiaProcessor.cs b/src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/ProtanopiaProcessor.cs index 511b3c89d..3c9281342 100644 --- a/src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/ProtanopiaProcessor.cs +++ b/src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/ProtanopiaProcessor.cs @@ -12,10 +12,8 @@ namespace ImageSharp.Processors /// Converts the colors of the image recreating Protanopia (Red-Blind) color blindness. /// /// The pixel format. - /// The packed format. uint, long, float. - public class ProtanopiaProcessor : ColorMatrixFilter - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class ProtanopiaProcessor : ColorMatrixFilter + where TColor : struct, IPackedPixel, IEquatable { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/TritanomalyProcessor.cs b/src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/TritanomalyProcessor.cs index 52aca09e0..cde693c42 100644 --- a/src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/TritanomalyProcessor.cs +++ b/src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/TritanomalyProcessor.cs @@ -12,10 +12,8 @@ namespace ImageSharp.Processors /// Converts the colors of the image recreating Tritanomaly (Blue-Weak) color blindness. /// /// The pixel format. - /// The packed format. uint, long, float. - public class TritanomalyProcessor : ColorMatrixFilter - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class TritanomalyProcessor : ColorMatrixFilter + where TColor : struct, IPackedPixel, IEquatable { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/TritanopiaProcessor.cs b/src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/TritanopiaProcessor.cs index 0a121c3ed..eb47c61c2 100644 --- a/src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/TritanopiaProcessor.cs +++ b/src/ImageSharp/Filters/Processors/ColorMatrix/ColorBlindness/TritanopiaProcessor.cs @@ -12,10 +12,8 @@ namespace ImageSharp.Processors /// Converts the colors of the image recreating Tritanopia (Blue-Blind) color blindness. /// /// The pixel format. - /// The packed format. uint, long, float. - public class TritanopiaProcessor : ColorMatrixFilter - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class TritanopiaProcessor : ColorMatrixFilter + where TColor : struct, IPackedPixel, IEquatable { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageSharp/Filters/Processors/ColorMatrix/ColorMatrixFilter.cs b/src/ImageSharp/Filters/Processors/ColorMatrix/ColorMatrixFilter.cs index f250b5a42..a3e54cdbb 100644 --- a/src/ImageSharp/Filters/Processors/ColorMatrix/ColorMatrixFilter.cs +++ b/src/ImageSharp/Filters/Processors/ColorMatrix/ColorMatrixFilter.cs @@ -13,10 +13,8 @@ namespace ImageSharp.Processors /// The color matrix filter. Inherit from this class to perform operation involving color matrices. /// /// The pixel format. - /// The packed format. uint, long, float. - public abstract class ColorMatrixFilter : ImageFilteringProcessor, IColorMatrixFilter - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public abstract class ColorMatrixFilter : ImageFilteringProcessor, IColorMatrixFilter + where TColor : struct, IPackedPixel, IEquatable { /// public abstract Matrix4x4 Matrix { get; } @@ -25,7 +23,7 @@ namespace ImageSharp.Processors public override bool Compand { get; set; } = true; /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { int startY = sourceRectangle.Y; int endY = sourceRectangle.Bottom; @@ -52,7 +50,7 @@ namespace ImageSharp.Processors Matrix4x4 matrix = this.Matrix; bool compand = this.Compand; - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) { Parallel.For( minY, diff --git a/src/ImageSharp/Filters/Processors/ColorMatrix/GrayscaleBt601Processor.cs b/src/ImageSharp/Filters/Processors/ColorMatrix/GrayscaleBt601Processor.cs index 53b131563..b3e30f04e 100644 --- a/src/ImageSharp/Filters/Processors/ColorMatrix/GrayscaleBt601Processor.cs +++ b/src/ImageSharp/Filters/Processors/ColorMatrix/GrayscaleBt601Processor.cs @@ -13,10 +13,8 @@ namespace ImageSharp.Processors /// ITU-R Recommendation BT.601 . /// /// The pixel format. - /// The packed format. uint, long, float. - public class GrayscaleBt601Processor : ColorMatrixFilter - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class GrayscaleBt601Processor : ColorMatrixFilter + where TColor : struct, IPackedPixel, IEquatable { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageSharp/Filters/Processors/ColorMatrix/GrayscaleBt709Processor.cs b/src/ImageSharp/Filters/Processors/ColorMatrix/GrayscaleBt709Processor.cs index e3bf2d4b7..24801b901 100644 --- a/src/ImageSharp/Filters/Processors/ColorMatrix/GrayscaleBt709Processor.cs +++ b/src/ImageSharp/Filters/Processors/ColorMatrix/GrayscaleBt709Processor.cs @@ -13,10 +13,8 @@ namespace ImageSharp.Processors /// ITU-R Recommendation BT.709 . /// /// The pixel format. - /// The packed format. uint, long, float. - public class GrayscaleBt709Processor : ColorMatrixFilter - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class GrayscaleBt709Processor : ColorMatrixFilter + where TColor : struct, IPackedPixel, IEquatable { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageSharp/Filters/Processors/ColorMatrix/HueProcessor.cs b/src/ImageSharp/Filters/Processors/ColorMatrix/HueProcessor.cs index c2fa370e8..a1de8eb0c 100644 --- a/src/ImageSharp/Filters/Processors/ColorMatrix/HueProcessor.cs +++ b/src/ImageSharp/Filters/Processors/ColorMatrix/HueProcessor.cs @@ -9,16 +9,14 @@ namespace ImageSharp.Processors using System.Numerics; /// - /// An to change the hue of an . + /// An to change the hue of an . /// /// The pixel format. - /// The packed format. uint, long, float. - public class HueProcessor : ColorMatrixFilter - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class HueProcessor : ColorMatrixFilter + where TColor : struct, IPackedPixel, IEquatable { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The new brightness of the image. Must be between -100 and 100. public HueProcessor(float angle) diff --git a/src/ImageSharp/Filters/Processors/ColorMatrix/IColorMatrixFilter.cs b/src/ImageSharp/Filters/Processors/ColorMatrix/IColorMatrixFilter.cs index 627098d66..9fcda4b95 100644 --- a/src/ImageSharp/Filters/Processors/ColorMatrix/IColorMatrixFilter.cs +++ b/src/ImageSharp/Filters/Processors/ColorMatrix/IColorMatrixFilter.cs @@ -13,10 +13,8 @@ namespace ImageSharp.Processors /// alter the image pixels. /// /// The pixel format. - /// The packed format. uint, long, float. - public interface IColorMatrixFilter : IImageFilteringProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public interface IColorMatrixFilter : IImageFilteringProcessor + where TColor : struct, IPackedPixel, IEquatable { /// /// Gets the used to alter the image. diff --git a/src/ImageSharp/Filters/Processors/ColorMatrix/KodachromeProcessor.cs b/src/ImageSharp/Filters/Processors/ColorMatrix/KodachromeProcessor.cs index fc797bb38..60b6a1d20 100644 --- a/src/ImageSharp/Filters/Processors/ColorMatrix/KodachromeProcessor.cs +++ b/src/ImageSharp/Filters/Processors/ColorMatrix/KodachromeProcessor.cs @@ -12,10 +12,8 @@ namespace ImageSharp.Processors /// Converts the colors of the image recreating an old Kodachrome camera effect. /// /// The pixel format. - /// The packed format. uint, long, float. - public class KodachromeProcessor : ColorMatrixFilter - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class KodachromeProcessor : ColorMatrixFilter + where TColor : struct, IPackedPixel, IEquatable { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageSharp/Filters/Processors/ColorMatrix/LomographProcessor.cs b/src/ImageSharp/Filters/Processors/ColorMatrix/LomographProcessor.cs index 055e664a0..d58e588be 100644 --- a/src/ImageSharp/Filters/Processors/ColorMatrix/LomographProcessor.cs +++ b/src/ImageSharp/Filters/Processors/ColorMatrix/LomographProcessor.cs @@ -12,10 +12,8 @@ namespace ImageSharp.Processors /// Converts the colors of the image recreating an old Lomograph effect. /// /// The pixel format. - /// The packed format. uint, long, float. - public class LomographProcessor : ColorMatrixFilter - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class LomographProcessor : ColorMatrixFilter + where TColor : struct, IPackedPixel, IEquatable { /// public override Matrix4x4 Matrix => new Matrix4x4() @@ -30,11 +28,11 @@ namespace ImageSharp.Processors }; /// - protected override void AfterApply(ImageBase source, Rectangle sourceRectangle) + protected override void AfterApply(ImageBase source, Rectangle sourceRectangle) { TColor packed = default(TColor); packed.PackFromVector4(new Color(0, 10, 0).ToVector4()); // Very dark (mostly black) lime green. - new VignetteProcessor { VignetteColor = packed }.Apply(source, sourceRectangle); + new VignetteProcessor { VignetteColor = packed }.Apply(source, sourceRectangle); } } } \ No newline at end of file diff --git a/src/ImageSharp/Filters/Processors/ColorMatrix/PolaroidProcessor.cs b/src/ImageSharp/Filters/Processors/ColorMatrix/PolaroidProcessor.cs index 485651504..73bc18e49 100644 --- a/src/ImageSharp/Filters/Processors/ColorMatrix/PolaroidProcessor.cs +++ b/src/ImageSharp/Filters/Processors/ColorMatrix/PolaroidProcessor.cs @@ -12,10 +12,8 @@ namespace ImageSharp.Processors /// Converts the colors of the image recreating an old Polaroid effect. /// /// The pixel format. - /// The packed format. uint, long, float. - public class PolaroidProcessor : ColorMatrixFilter - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class PolaroidProcessor : ColorMatrixFilter + where TColor : struct, IPackedPixel, IEquatable { /// public override Matrix4x4 Matrix => new Matrix4x4() @@ -36,15 +34,15 @@ namespace ImageSharp.Processors }; /// - protected override void AfterApply(ImageBase source, Rectangle sourceRectangle) + protected override void AfterApply(ImageBase source, Rectangle sourceRectangle) { TColor packedV = default(TColor); packedV.PackFromVector4(new Color(102, 34, 0).ToVector4()); // Very dark orange [Brown tone] - new VignetteProcessor { VignetteColor = packedV }.Apply(source, sourceRectangle); + new VignetteProcessor { VignetteColor = packedV }.Apply(source, sourceRectangle); TColor packedG = default(TColor); packedG.PackFromVector4(new Color(255, 153, 102, 178).ToVector4()); // Light orange - new GlowProcessor { GlowColor = packedG, Radius = source.Width / 4F }.Apply(source, sourceRectangle); + new GlowProcessor { GlowColor = packedG, Radius = source.Width / 4F }.Apply(source, sourceRectangle); } } } \ No newline at end of file diff --git a/src/ImageSharp/Filters/Processors/ColorMatrix/SaturationProcessor.cs b/src/ImageSharp/Filters/Processors/ColorMatrix/SaturationProcessor.cs index e578e77cd..71bb49c92 100644 --- a/src/ImageSharp/Filters/Processors/ColorMatrix/SaturationProcessor.cs +++ b/src/ImageSharp/Filters/Processors/ColorMatrix/SaturationProcessor.cs @@ -9,16 +9,14 @@ namespace ImageSharp.Processors using System.Numerics; /// - /// An to change the saturation of an . + /// An to change the saturation of an . /// /// The pixel format. - /// The packed format. uint, long, float. - public class SaturationProcessor : ColorMatrixFilter - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class SaturationProcessor : ColorMatrixFilter + where TColor : struct, IPackedPixel, IEquatable { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The new saturation of the image. Must be between -100 and 100. /// diff --git a/src/ImageSharp/Filters/Processors/ColorMatrix/SepiaProcessor.cs b/src/ImageSharp/Filters/Processors/ColorMatrix/SepiaProcessor.cs index 8382af02a..8353cfa0b 100644 --- a/src/ImageSharp/Filters/Processors/ColorMatrix/SepiaProcessor.cs +++ b/src/ImageSharp/Filters/Processors/ColorMatrix/SepiaProcessor.cs @@ -13,10 +13,8 @@ namespace ImageSharp.Processors /// The formula used matches the svg specification. /// /// The pixel format. - /// The packed format. uint, long, float. - public class SepiaProcessor : ColorMatrixFilter - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class SepiaProcessor : ColorMatrixFilter + where TColor : struct, IPackedPixel, IEquatable { /// public override Matrix4x4 Matrix => new Matrix4x4 diff --git a/src/ImageSharp/Filters/Processors/Convolution/BoxBlurProcessor.cs b/src/ImageSharp/Filters/Processors/Convolution/BoxBlurProcessor.cs index 544c76807..7780992bb 100644 --- a/src/ImageSharp/Filters/Processors/Convolution/BoxBlurProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Convolution/BoxBlurProcessor.cs @@ -11,10 +11,8 @@ namespace ImageSharp.Processors /// Applies a Box blur sampler to the image. /// /// The pixel format. - /// The packed format. uint, long, float. - public class BoxBlurProcessor : ImageFilteringProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class BoxBlurProcessor : ImageFilteringProcessor + where TColor : struct, IPackedPixel, IEquatable { /// /// The maximum size of the kernel in either direction. @@ -22,7 +20,7 @@ namespace ImageSharp.Processors private readonly int kernelSize; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// The 'radius' value representing the size of the area to sample. @@ -45,9 +43,9 @@ namespace ImageSharp.Processors public float[][] KernelY { get; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { - new Convolution2PassProcessor(this.KernelX, this.KernelY).Apply(source, sourceRectangle); + new Convolution2PassProcessor(this.KernelX, this.KernelY).Apply(source, sourceRectangle); } /// diff --git a/src/ImageSharp/Filters/Processors/Convolution/Convolution2DProcessor.cs b/src/ImageSharp/Filters/Processors/Convolution/Convolution2DProcessor.cs index 0eb84d41a..e00495302 100644 --- a/src/ImageSharp/Filters/Processors/Convolution/Convolution2DProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Convolution/Convolution2DProcessor.cs @@ -13,13 +13,11 @@ namespace ImageSharp.Processors /// Defines a sampler that uses two one-dimensional matrices to perform convolution against an image. /// /// The pixel format. - /// The packed format. uint, long, float. - public class Convolution2DProcessor : ImageFilteringProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class Convolution2DProcessor : ImageFilteringProcessor + where TColor : struct, IPackedPixel, IEquatable { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The horizontal gradient operator. /// The vertical gradient operator. @@ -40,7 +38,7 @@ namespace ImageSharp.Processors public float[][] KernelY { get; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { int kernelYHeight = this.KernelY.Length; int kernelYWidth = this.KernelY[0].Length; @@ -57,8 +55,8 @@ namespace ImageSharp.Processors int maxX = endX - 1; TColor[] target = new TColor[source.Width * source.Height]; - using (PixelAccessor sourcePixels = source.Lock()) - using (PixelAccessor targetPixels = target.Lock(source.Width, source.Height)) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock(source.Width, source.Height)) { Parallel.For( startY, diff --git a/src/ImageSharp/Filters/Processors/Convolution/Convolution2PassProcessor.cs b/src/ImageSharp/Filters/Processors/Convolution/Convolution2PassProcessor.cs index bc33cea2e..f90440293 100644 --- a/src/ImageSharp/Filters/Processors/Convolution/Convolution2PassProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Convolution/Convolution2PassProcessor.cs @@ -13,13 +13,11 @@ namespace ImageSharp.Processors /// Defines a sampler that uses two one-dimensional matrices to perform two-pass convolution against an image. /// /// The pixel format. - /// The packed format. uint, long, float. - public class Convolution2PassProcessor : ImageFilteringProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class Convolution2PassProcessor : ImageFilteringProcessor + where TColor : struct, IPackedPixel, IEquatable { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The horizontal gradient operator. /// The vertical gradient operator. @@ -40,7 +38,7 @@ namespace ImageSharp.Processors public float[][] KernelY { get; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { float[][] kernelX = this.KernelX; float[][] kernelY = this.KernelY; @@ -57,7 +55,7 @@ namespace ImageSharp.Processors } /// - /// Applies the process to the specified portion of the specified at the specified location + /// Applies the process to the specified portion of the specified at the specified location /// and with the specified size. /// /// The image width. @@ -82,8 +80,8 @@ namespace ImageSharp.Processors int maxY = endY - 1; int maxX = endX - 1; - using (PixelAccessor sourcePixels = source.Lock(width, height)) - using (PixelAccessor targetPixels = target.Lock(width, height)) + using (PixelAccessor sourcePixels = source.Lock(width, height)) + using (PixelAccessor targetPixels = target.Lock(width, height)) { Parallel.For( startY, diff --git a/src/ImageSharp/Filters/Processors/Convolution/ConvolutionProcessor.cs b/src/ImageSharp/Filters/Processors/Convolution/ConvolutionProcessor.cs index 4b7dbf171..e4d3f4d42 100644 --- a/src/ImageSharp/Filters/Processors/Convolution/ConvolutionProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Convolution/ConvolutionProcessor.cs @@ -13,13 +13,11 @@ namespace ImageSharp.Processors /// Defines a sampler that uses a 2 dimensional matrix to perform convolution against an image. /// /// The pixel format. - /// The packed format. uint, long, float. - public class ConvolutionProcessor : ImageFilteringProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class ConvolutionProcessor : ImageFilteringProcessor + where TColor : struct, IPackedPixel, IEquatable { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The 2d gradient operator. public ConvolutionProcessor(float[][] kernelXY) @@ -33,7 +31,7 @@ namespace ImageSharp.Processors public virtual float[][] KernelXY { get; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { float[][] kernelX = this.KernelXY; int kernelLength = kernelX.GetLength(0); @@ -47,8 +45,8 @@ namespace ImageSharp.Processors int maxX = endX - 1; TColor[] target = new TColor[source.Width * source.Height]; - using (PixelAccessor sourcePixels = source.Lock()) - using (PixelAccessor targetPixels = target.Lock(source.Width, source.Height)) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock(source.Width, source.Height)) { Parallel.For( startY, diff --git a/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/EdgeDetector2DProcessor.cs b/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/EdgeDetector2DProcessor.cs index 7b126c3ee..446771c26 100644 --- a/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/EdgeDetector2DProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/EdgeDetector2DProcessor.cs @@ -11,10 +11,8 @@ namespace ImageSharp.Processors /// Defines a sampler that detects edges within an image using two one-dimensional matrices. /// /// The pixel format. - /// The packed format. uint, long, float. - public abstract class EdgeDetector2DProcessor : ImageFilteringProcessor, IEdgeDetectorProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public abstract class EdgeDetector2DProcessor : ImageFilteringProcessor, IEdgeDetectorProcessor + where TColor : struct, IPackedPixel, IEquatable { /// /// Gets the horizontal gradient operator. @@ -30,17 +28,17 @@ namespace ImageSharp.Processors public bool Grayscale { get; set; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { - new Convolution2DProcessor(this.KernelX, this.KernelY).Apply(source, sourceRectangle); + new Convolution2DProcessor(this.KernelX, this.KernelY).Apply(source, sourceRectangle); } /// - protected override void BeforeApply(ImageBase source, Rectangle sourceRectangle) + protected override void BeforeApply(ImageBase source, Rectangle sourceRectangle) { if (this.Grayscale) { - new GrayscaleBt709Processor().Apply(source, sourceRectangle); + new GrayscaleBt709Processor().Apply(source, sourceRectangle); } } } diff --git a/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs b/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs index 1fa527c6e..b9f5e449e 100644 --- a/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs @@ -13,10 +13,8 @@ namespace ImageSharp.Processors /// Defines a sampler that detects edges within an image using a eight two dimensional matrices. /// /// The pixel format. - /// The packed format. uint, long, float. - public abstract class EdgeDetectorCompassProcessor : ImageFilteringProcessor, IEdgeDetectorProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public abstract class EdgeDetectorCompassProcessor : ImageFilteringProcessor, IEdgeDetectorProcessor + where TColor : struct, IPackedPixel, IEquatable { /// /// Gets the North gradient operator @@ -62,7 +60,7 @@ namespace ImageSharp.Processors public bool Grayscale { get; set; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { float[][][] kernels = { this.North, this.NorthWest, this.West, this.SouthWest, this.South, this.SouthEast, this.East, this.NorthEast }; @@ -78,9 +76,9 @@ namespace ImageSharp.Processors int maxY = Math.Min(source.Height, endY); // First run. - ImageBase target = new Image(source.Width, source.Height); + ImageBase target = new Image(source.Width, source.Height); target.ClonePixels(source.Width, source.Height, source.Pixels); - new ConvolutionProcessor(kernels[0]).Apply(target, sourceRectangle); + new ConvolutionProcessor(kernels[0]).Apply(target, sourceRectangle); if (kernels.Length == 1) { @@ -106,13 +104,13 @@ namespace ImageSharp.Processors for (int i = 1; i < kernels.Length; i++) { // Create a clone for each pass and copy the offset pixels across. - ImageBase pass = new Image(source.Width, source.Height); + ImageBase pass = new Image(source.Width, source.Height); pass.ClonePixels(source.Width, source.Height, source.Pixels); - new ConvolutionProcessor(kernels[i]).Apply(pass, sourceRectangle); + new ConvolutionProcessor(kernels[i]).Apply(pass, sourceRectangle); - using (PixelAccessor passPixels = pass.Lock()) - using (PixelAccessor targetPixels = target.Lock()) + using (PixelAccessor passPixels = pass.Lock()) + using (PixelAccessor targetPixels = target.Lock()) { Parallel.For( minY, @@ -138,11 +136,11 @@ namespace ImageSharp.Processors } /// - protected override void BeforeApply(ImageBase source, Rectangle sourceRectangle) + protected override void BeforeApply(ImageBase source, Rectangle sourceRectangle) { if (this.Grayscale) { - new GrayscaleBt709Processor().Apply(source, sourceRectangle); + new GrayscaleBt709Processor().Apply(source, sourceRectangle); } } } diff --git a/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/EdgeDetectorProcessor.cs b/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/EdgeDetectorProcessor.cs index e454b7484..7542a3631 100644 --- a/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/EdgeDetectorProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/EdgeDetectorProcessor.cs @@ -11,10 +11,8 @@ namespace ImageSharp.Processors /// Defines a sampler that detects edges within an image using a single two dimensional matrix. /// /// The pixel format. - /// The packed format. uint, long, float. - public abstract class EdgeDetectorProcessor : ImageFilteringProcessor, IEdgeDetectorProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public abstract class EdgeDetectorProcessor : ImageFilteringProcessor, IEdgeDetectorProcessor + where TColor : struct, IPackedPixel, IEquatable { /// public bool Grayscale { get; set; } @@ -25,17 +23,17 @@ namespace ImageSharp.Processors public abstract float[][] KernelXY { get; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { - new ConvolutionProcessor(this.KernelXY).Apply(source, sourceRectangle); + new ConvolutionProcessor(this.KernelXY).Apply(source, sourceRectangle); } /// - protected override void BeforeApply(ImageBase source, Rectangle sourceRectangle) + protected override void BeforeApply(ImageBase source, Rectangle sourceRectangle) { if (this.Grayscale) { - new GrayscaleBt709Processor().Apply(source, sourceRectangle); + new GrayscaleBt709Processor().Apply(source, sourceRectangle); } } } diff --git a/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/IEdgeDetectorProcessor.cs b/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/IEdgeDetectorProcessor.cs index 9e8c4cc42..f98fdf56b 100644 --- a/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/IEdgeDetectorProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/IEdgeDetectorProcessor.cs @@ -11,10 +11,8 @@ namespace ImageSharp.Processors /// Provides properties and methods allowing the detection of edges within an image. /// /// The pixel format. - /// The packed format. uint, long, float. - public interface IEdgeDetectorProcessor : IImageFilteringProcessor, IEdgeDetectorProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public interface IEdgeDetectorProcessor : IImageFilteringProcessor, IEdgeDetectorProcessor + where TColor : struct, IPackedPixel, IEquatable { } diff --git a/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs b/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs index cf2fec302..84d14e7cf 100644 --- a/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs @@ -13,11 +13,9 @@ namespace ImageSharp.Processors /// /// /// The pixel format. - /// The packed format. uint, long, float. [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] - public class KayyaliProcessor : EdgeDetector2DProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class KayyaliProcessor : EdgeDetector2DProcessor + where TColor : struct, IPackedPixel, IEquatable { /// /// The horizontal gradient operator. diff --git a/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/KirschProcessor.cs b/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/KirschProcessor.cs index d65bfe304..6bc440e23 100644 --- a/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/KirschProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/KirschProcessor.cs @@ -12,11 +12,9 @@ namespace ImageSharp.Processors /// /// /// The pixel format. - /// The packed format. uint, long, float. [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] - public class KirschProcessor : EdgeDetectorCompassProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class KirschProcessor : EdgeDetectorCompassProcessor + where TColor : struct, IPackedPixel, IEquatable { /// /// The North gradient operator diff --git a/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs b/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs index eaf68178e..89e29e211 100644 --- a/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs +++ b/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs @@ -13,11 +13,9 @@ namespace ImageSharp.Processors /// /// /// The pixel format. - /// The packed format. uint, long, float. [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] - public class Laplacian3X3Processor : EdgeDetectorProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class Laplacian3X3Processor : EdgeDetectorProcessor + where TColor : struct, IPackedPixel, IEquatable { /// /// The 2d gradient operator. diff --git a/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs b/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs index 00735b4ec..7b8e96544 100644 --- a/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs +++ b/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs @@ -13,11 +13,9 @@ namespace ImageSharp.Processors /// /// /// The pixel format. - /// The packed format. uint, long, float. [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] - public class Laplacian5X5Processor : EdgeDetectorProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class Laplacian5X5Processor : EdgeDetectorProcessor + where TColor : struct, IPackedPixel, IEquatable { /// /// The 2d gradient operator. diff --git a/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs b/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs index 95a3f717d..112d1c517 100644 --- a/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs @@ -13,11 +13,9 @@ namespace ImageSharp.Processors /// /// /// The pixel format. - /// The packed format. uint, long, float. [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] - public class LaplacianOfGaussianProcessor : EdgeDetectorProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class LaplacianOfGaussianProcessor : EdgeDetectorProcessor + where TColor : struct, IPackedPixel, IEquatable { /// /// The 2d gradient operator. diff --git a/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/PrewittProcessor.cs b/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/PrewittProcessor.cs index f91db77e3..a3d719ba7 100644 --- a/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/PrewittProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/PrewittProcessor.cs @@ -13,11 +13,9 @@ namespace ImageSharp.Processors /// /// /// The pixel format. - /// The packed format. uint, long, float. [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] - public class PrewittProcessor : EdgeDetector2DProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class PrewittProcessor : EdgeDetector2DProcessor + where TColor : struct, IPackedPixel, IEquatable { /// /// The horizontal gradient operator. diff --git a/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs b/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs index abb4914f5..f7586e11f 100644 --- a/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs @@ -13,11 +13,9 @@ namespace ImageSharp.Processors /// /// /// The pixel format. - /// The packed format. uint, long, float. [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] - public class RobertsCrossProcessor : EdgeDetector2DProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class RobertsCrossProcessor : EdgeDetector2DProcessor + where TColor : struct, IPackedPixel, IEquatable { /// /// The horizontal gradient operator. diff --git a/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs b/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs index 2bddf0d3e..cb05599bf 100644 --- a/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs @@ -12,11 +12,9 @@ namespace ImageSharp.Processors /// /// /// The pixel format. - /// The packed format. uint, long, float. [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] - public class RobinsonProcessor : EdgeDetectorCompassProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class RobinsonProcessor : EdgeDetectorCompassProcessor + where TColor : struct, IPackedPixel, IEquatable { /// /// The North gradient operator diff --git a/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/ScharrProcessor.cs b/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/ScharrProcessor.cs index 1755e6568..3c9c818d3 100644 --- a/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/ScharrProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/ScharrProcessor.cs @@ -13,11 +13,9 @@ namespace ImageSharp.Processors /// /// /// The pixel format. - /// The packed format. uint, long, float. [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] - public class ScharrProcessor : EdgeDetector2DProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class ScharrProcessor : EdgeDetector2DProcessor + where TColor : struct, IPackedPixel, IEquatable { /// /// The horizontal gradient operator. diff --git a/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/SobelProcessor.cs b/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/SobelProcessor.cs index 0017cf545..ebca2018b 100644 --- a/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/SobelProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/SobelProcessor.cs @@ -13,11 +13,9 @@ namespace ImageSharp.Processors /// /// /// The pixel format. - /// The packed format. uint, long, float. [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] - public class SobelProcessor : EdgeDetector2DProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class SobelProcessor : EdgeDetector2DProcessor + where TColor : struct, IPackedPixel, IEquatable { /// /// The horizontal gradient operator. diff --git a/src/ImageSharp/Filters/Processors/Convolution/GaussianBlurProcessor.cs b/src/ImageSharp/Filters/Processors/Convolution/GaussianBlurProcessor.cs index 1ff2484e2..543fe26af 100644 --- a/src/ImageSharp/Filters/Processors/Convolution/GaussianBlurProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Convolution/GaussianBlurProcessor.cs @@ -11,10 +11,8 @@ namespace ImageSharp.Processors /// Applies a Gaussian blur sampler to the image. /// /// The pixel format. - /// The packed format. uint, long, float. - public class GaussianBlurProcessor : ImageFilteringProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class GaussianBlurProcessor : ImageFilteringProcessor + where TColor : struct, IPackedPixel, IEquatable { /// /// The maximum size of the kernel in either direction. @@ -27,7 +25,7 @@ namespace ImageSharp.Processors private readonly float sigma; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The 'sigma' value representing the weight of the blur. public GaussianBlurProcessor(float sigma = 3f) @@ -39,7 +37,7 @@ namespace ImageSharp.Processors } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// The 'radius' value representing the size of the area to sample. @@ -53,7 +51,7 @@ namespace ImageSharp.Processors } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// The 'sigma' value representing the weight of the blur. @@ -81,9 +79,9 @@ namespace ImageSharp.Processors public float[][] KernelY { get; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { - new Convolution2PassProcessor(this.KernelX, this.KernelY).Apply(source, sourceRectangle); + new Convolution2PassProcessor(this.KernelX, this.KernelY).Apply(source, sourceRectangle); } /// diff --git a/src/ImageSharp/Filters/Processors/Convolution/GaussianSharpenProcessor.cs b/src/ImageSharp/Filters/Processors/Convolution/GaussianSharpenProcessor.cs index d9865e481..e2e9b418b 100644 --- a/src/ImageSharp/Filters/Processors/Convolution/GaussianSharpenProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Convolution/GaussianSharpenProcessor.cs @@ -11,10 +11,8 @@ namespace ImageSharp.Processors /// Applies a Gaussian sharpening sampler to the image. /// /// The pixel format. - /// The packed format. uint, long, float. - public class GaussianSharpenProcessor : ImageFilteringProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class GaussianSharpenProcessor : ImageFilteringProcessor + where TColor : struct, IPackedPixel, IEquatable { /// /// The maximum size of the kernel in either direction. @@ -27,7 +25,7 @@ namespace ImageSharp.Processors private readonly float sigma; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// The 'sigma' value representing the weight of the sharpening. @@ -41,7 +39,7 @@ namespace ImageSharp.Processors } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// The 'radius' value representing the size of the area to sample. @@ -55,7 +53,7 @@ namespace ImageSharp.Processors } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// The 'sigma' value representing the weight of the sharpen. @@ -83,9 +81,9 @@ namespace ImageSharp.Processors public float[][] KernelY { get; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { - new Convolution2PassProcessor(this.KernelX, this.KernelY).Apply(source, sourceRectangle); + new Convolution2PassProcessor(this.KernelX, this.KernelY).Apply(source, sourceRectangle); } /// diff --git a/src/ImageSharp/Filters/Processors/Effects/AlphaProcessor.cs b/src/ImageSharp/Filters/Processors/Effects/AlphaProcessor.cs index 2e29c4810..0e9406ee5 100644 --- a/src/ImageSharp/Filters/Processors/Effects/AlphaProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Effects/AlphaProcessor.cs @@ -10,16 +10,14 @@ namespace ImageSharp.Processors using System.Threading.Tasks; /// - /// An to change the alpha component of an . + /// An to change the alpha component of an . /// /// The pixel format. - /// The packed format. uint, long, float. - public class AlphaProcessor : ImageFilteringProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class AlphaProcessor : ImageFilteringProcessor + where TColor : struct, IPackedPixel, IEquatable { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The percentage to adjust the opacity of the image. Must be between 0 and 100. /// @@ -37,7 +35,7 @@ namespace ImageSharp.Processors public int Value { get; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { float alpha = this.Value / 100F; @@ -65,7 +63,7 @@ namespace ImageSharp.Processors Vector4 alphaVector = new Vector4(1, 1, 1, alpha); - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) { Parallel.For( minY, diff --git a/src/ImageSharp/Filters/Processors/Effects/BackgroundColorProcessor.cs b/src/ImageSharp/Filters/Processors/Effects/BackgroundColorProcessor.cs index 26e5f8584..122c5a0ff 100644 --- a/src/ImageSharp/Filters/Processors/Effects/BackgroundColorProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Effects/BackgroundColorProcessor.cs @@ -13,10 +13,8 @@ namespace ImageSharp.Processors /// Sets the background color of the image. /// /// The pixel format. - /// The packed format. uint, long, float. - public class BackgroundColorProcessor : ImageFilteringProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class BackgroundColorProcessor : ImageFilteringProcessor + where TColor : struct, IPackedPixel, IEquatable { /// /// The epsilon for comparing floating point numbers. @@ -24,7 +22,7 @@ namespace ImageSharp.Processors private const float Epsilon = 0.001f; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The to set the background color to. public BackgroundColorProcessor(TColor color) @@ -38,7 +36,7 @@ namespace ImageSharp.Processors public TColor Value { get; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { int startY = sourceRectangle.Y; int endY = sourceRectangle.Bottom; @@ -64,7 +62,7 @@ namespace ImageSharp.Processors Vector4 backgroundColor = this.Value.ToVector4(); - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) { Parallel.For( minY, diff --git a/src/ImageSharp/Filters/Processors/Effects/BrightnessProcessor.cs b/src/ImageSharp/Filters/Processors/Effects/BrightnessProcessor.cs index fdcdd094a..8bc021618 100644 --- a/src/ImageSharp/Filters/Processors/Effects/BrightnessProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Effects/BrightnessProcessor.cs @@ -10,16 +10,14 @@ namespace ImageSharp.Processors using System.Threading.Tasks; /// - /// An to change the brightness of an . + /// An to change the brightness of an . /// /// The pixel format. - /// The packed format. uint, long, float. - public class BrightnessProcessor : ImageFilteringProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class BrightnessProcessor : ImageFilteringProcessor + where TColor : struct, IPackedPixel, IEquatable { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The new brightness of the image. Must be between -100 and 100. /// @@ -37,7 +35,7 @@ namespace ImageSharp.Processors public int Value { get; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { float brightness = this.Value / 100F; @@ -63,7 +61,7 @@ namespace ImageSharp.Processors startY = 0; } - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) { Parallel.For( minY, diff --git a/src/ImageSharp/Filters/Processors/Effects/ContrastProcessor.cs b/src/ImageSharp/Filters/Processors/Effects/ContrastProcessor.cs index 640a32900..ba830b12a 100644 --- a/src/ImageSharp/Filters/Processors/Effects/ContrastProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Effects/ContrastProcessor.cs @@ -10,16 +10,14 @@ namespace ImageSharp.Processors using System.Threading.Tasks; /// - /// An to change the contrast of an . + /// An to change the contrast of an . /// /// The pixel format. - /// The packed format. long, float. - public class ContrastProcessor : ImageFilteringProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class ContrastProcessor : ImageFilteringProcessor + where TColor : struct, IPackedPixel, IEquatable { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The new contrast of the image. Must be between -100 and 100. /// @@ -37,7 +35,7 @@ namespace ImageSharp.Processors public int Value { get; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { float contrast = (100F + this.Value) / 100F; @@ -65,7 +63,7 @@ namespace ImageSharp.Processors startY = 0; } - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) { Parallel.For( minY, diff --git a/src/ImageSharp/Filters/Processors/Effects/InvertProcessor.cs b/src/ImageSharp/Filters/Processors/Effects/InvertProcessor.cs index 0a8dea72f..e34d15f05 100644 --- a/src/ImageSharp/Filters/Processors/Effects/InvertProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Effects/InvertProcessor.cs @@ -10,16 +10,14 @@ namespace ImageSharp.Processors using System.Threading.Tasks; /// - /// An to invert the colors of an . + /// An to invert the colors of an . /// /// The pixel format. - /// The packed format. uint, long, float. - public class InvertProcessor : ImageFilteringProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class InvertProcessor : ImageFilteringProcessor + where TColor : struct, IPackedPixel, IEquatable { /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { int startY = sourceRectangle.Y; int endY = sourceRectangle.Bottom; @@ -44,7 +42,7 @@ namespace ImageSharp.Processors startY = 0; } - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) { Parallel.For( minY, diff --git a/src/ImageSharp/Filters/Processors/Effects/OilPaintingProcessor.cs b/src/ImageSharp/Filters/Processors/Effects/OilPaintingProcessor.cs index b48ffa809..b0c886acf 100644 --- a/src/ImageSharp/Filters/Processors/Effects/OilPaintingProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Effects/OilPaintingProcessor.cs @@ -10,17 +10,15 @@ namespace ImageSharp.Processors using System.Threading.Tasks; /// - /// An to apply an oil painting effect to an . + /// An to apply an oil painting effect to an . /// /// Adapted from by Dewald Esterhuizen. /// The pixel format. - /// The packed format. uint, long, float. - public class OilPaintingProcessor : ImageFilteringProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class OilPaintingProcessor : ImageFilteringProcessor + where TColor : struct, IPackedPixel, IEquatable { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// The number of intensity levels. Higher values result in a broader range of color intensities forming part of the result image. @@ -48,7 +46,7 @@ namespace ImageSharp.Processors public int BrushSize { get; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { int startY = sourceRectangle.Y; int endY = sourceRectangle.Bottom; @@ -70,8 +68,8 @@ namespace ImageSharp.Processors } TColor[] target = new TColor[source.Width * source.Height]; - using (PixelAccessor sourcePixels = source.Lock()) - using (PixelAccessor targetPixels = target.Lock(source.Width, source.Height)) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock(source.Width, source.Height)) { Parallel.For( minY, diff --git a/src/ImageSharp/Filters/Processors/Effects/PixelateProcessor.cs b/src/ImageSharp/Filters/Processors/Effects/PixelateProcessor.cs index b97545962..a24df71aa 100644 --- a/src/ImageSharp/Filters/Processors/Effects/PixelateProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Effects/PixelateProcessor.cs @@ -10,16 +10,14 @@ namespace ImageSharp.Processors using System.Threading.Tasks; /// - /// An to pixelate the colors of an . + /// An to pixelate the colors of an . /// /// The pixel format. - /// The packed format. uint, long, float. - public class PixelateProcessor : ImageFilteringProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class PixelateProcessor : ImageFilteringProcessor + where TColor : struct, IPackedPixel, IEquatable { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The size of the pixels. Must be greater than 0. /// @@ -37,7 +35,7 @@ namespace ImageSharp.Processors public int Value { get; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { int startY = sourceRectangle.Y; int endY = sourceRectangle.Bottom; @@ -67,8 +65,8 @@ namespace ImageSharp.Processors IEnumerable range = EnumerableExtensions.SteppedRange(minY, i => i < maxY, size); TColor[] target = new TColor[source.Width * source.Height]; - using (PixelAccessor sourcePixels = source.Lock()) - using (PixelAccessor targetPixels = target.Lock(source.Width, source.Height)) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock(source.Width, source.Height)) { Parallel.ForEach( range, diff --git a/src/ImageSharp/Filters/Processors/IImageFilteringProcessor.cs b/src/ImageSharp/Filters/Processors/IImageFilteringProcessor.cs index 73b48ef0b..a121caa3a 100644 --- a/src/ImageSharp/Filters/Processors/IImageFilteringProcessor.cs +++ b/src/ImageSharp/Filters/Processors/IImageFilteringProcessor.cs @@ -11,13 +11,11 @@ namespace ImageSharp.Processors /// Encapsulates methods to alter the pixels of an image. The processor operates on the original source pixels. /// /// The pixel format. - /// The packed format. uint, long, float. - public interface IImageFilteringProcessor : IImageProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public interface IImageFilteringProcessor : IImageProcessor + where TColor : struct, IPackedPixel, IEquatable { /// - /// Applies the process to the specified portion of the specified . + /// Applies the process to the specified portion of the specified . /// /// The source image. Cannot be null. /// @@ -33,6 +31,6 @@ namespace ImageSharp.Processors /// /// doesnt fit the dimension of the image. /// - void Apply(ImageBase source, Rectangle sourceRectangle); + void Apply(ImageBase source, Rectangle sourceRectangle); } } diff --git a/src/ImageSharp/Filters/Processors/ImageFilteringProcessor.cs b/src/ImageSharp/Filters/Processors/ImageFilteringProcessor.cs index 724645215..f61731651 100644 --- a/src/ImageSharp/Filters/Processors/ImageFilteringProcessor.cs +++ b/src/ImageSharp/Filters/Processors/ImageFilteringProcessor.cs @@ -11,13 +11,11 @@ namespace ImageSharp.Processors /// Encapsulates methods to alter the pixels of an image. The processor operates on the original source pixels. /// /// The pixel format. - /// The packed format. uint, long, float. - public abstract class ImageFilteringProcessor : ImageProcessor, IImageFilteringProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public abstract class ImageFilteringProcessor : ImageProcessor, IImageFilteringProcessor + where TColor : struct, IPackedPixel, IEquatable { /// - public void Apply(ImageBase source, Rectangle sourceRectangle) + public void Apply(ImageBase source, Rectangle sourceRectangle) { try { @@ -40,19 +38,19 @@ namespace ImageSharp.Processors /// /// The structure that specifies the portion of the image object to draw. /// - protected virtual void BeforeApply(ImageBase source, Rectangle sourceRectangle) + protected virtual void BeforeApply(ImageBase source, Rectangle sourceRectangle) { } /// - /// Applies the process to the specified portion of the specified at the specified location + /// Applies the process to the specified portion of the specified at the specified location /// and with the specified size. /// /// The source image. Cannot be null. /// /// The structure that specifies the portion of the image object to draw. /// - protected abstract void OnApply(ImageBase source, Rectangle sourceRectangle); + protected abstract void OnApply(ImageBase source, Rectangle sourceRectangle); /// /// This method is called after the process is applied to prepare the processor. @@ -61,7 +59,7 @@ namespace ImageSharp.Processors /// /// The structure that specifies the portion of the image object to draw. /// - protected virtual void AfterApply(ImageBase source, Rectangle sourceRectangle) + protected virtual void AfterApply(ImageBase source, Rectangle sourceRectangle) { } } diff --git a/src/ImageSharp/Filters/Processors/Overlays/GlowProcessor.cs b/src/ImageSharp/Filters/Processors/Overlays/GlowProcessor.cs index 393f0549a..36a0b1a57 100644 --- a/src/ImageSharp/Filters/Processors/Overlays/GlowProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Overlays/GlowProcessor.cs @@ -10,16 +10,14 @@ namespace ImageSharp.Processors using System.Threading.Tasks; /// - /// An that applies a radial glow effect an . + /// An that applies a radial glow effect an . /// /// The pixel format. - /// The packed format. uint, long, float. - public class GlowProcessor : ImageFilteringProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class GlowProcessor : ImageFilteringProcessor + where TColor : struct, IPackedPixel, IEquatable { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// public GlowProcessor() { @@ -39,7 +37,7 @@ namespace ImageSharp.Processors public float Radius { get; set; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { int startY = sourceRectangle.Y; int endY = sourceRectangle.Bottom; @@ -66,7 +64,7 @@ namespace ImageSharp.Processors startY = 0; } - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) { Parallel.For( minY, diff --git a/src/ImageSharp/Filters/Processors/Overlays/VignetteProcessor.cs b/src/ImageSharp/Filters/Processors/Overlays/VignetteProcessor.cs index e30a45b95..318b9063a 100644 --- a/src/ImageSharp/Filters/Processors/Overlays/VignetteProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Overlays/VignetteProcessor.cs @@ -10,16 +10,14 @@ namespace ImageSharp.Processors using System.Threading.Tasks; /// - /// An that applies a radial vignette effect to an . + /// An that applies a radial vignette effect to an . /// /// The pixel format. - /// The packed format. uint, long, float. - public class VignetteProcessor : ImageFilteringProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class VignetteProcessor : ImageFilteringProcessor + where TColor : struct, IPackedPixel, IEquatable { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// public VignetteProcessor() { @@ -44,7 +42,7 @@ namespace ImageSharp.Processors public float RadiusY { get; set; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { int startY = sourceRectangle.Y; int endY = sourceRectangle.Bottom; @@ -73,7 +71,7 @@ namespace ImageSharp.Processors startY = 0; } - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) { Parallel.For( minY, diff --git a/src/ImageSharp/Filters/Processors/Transforms/CompandingResizeProcessor.cs b/src/ImageSharp/Filters/Processors/Transforms/CompandingResizeProcessor.cs index ced5976ee..80f02c18f 100644 --- a/src/ImageSharp/Filters/Processors/Transforms/CompandingResizeProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Transforms/CompandingResizeProcessor.cs @@ -14,13 +14,11 @@ namespace ImageSharp.Processors /// This version will expand and compress the image to and from a linear color space during processing. /// /// The pixel format. - /// The packed format. uint, long, float. - public class CompandingResizeProcessor : ResamplingWeightedProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class CompandingResizeProcessor : ResamplingWeightedProcessor + where TColor : struct, IPackedPixel, IEquatable { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The sampler to perform the resize operation. /// The target width. @@ -31,7 +29,7 @@ namespace ImageSharp.Processors } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The sampler to perform the resize operation. /// The target width. @@ -48,7 +46,7 @@ namespace ImageSharp.Processors public override bool Compand { get; set; } = true; /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { // Jump out, we'll deal with that later. if (source.Width == this.Width && source.Height == this.Height && sourceRectangle == this.ResizeRectangle) @@ -76,8 +74,8 @@ namespace ImageSharp.Processors float widthFactor = sourceRectangle.Width / (float)this.ResizeRectangle.Width; float heightFactor = sourceRectangle.Height / (float)this.ResizeRectangle.Height; - using (PixelAccessor sourcePixels = source.Lock()) - using (PixelAccessor targetPixels = target.Lock(width, height)) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock(width, height)) { Parallel.For( minY, @@ -106,9 +104,9 @@ namespace ImageSharp.Processors // First process the columns. Since we are not using multiple threads startY and endY // are the upper and lower bounds of the source rectangle. TColor[] firstPass = new TColor[width * source.Height]; - using (PixelAccessor sourcePixels = source.Lock()) - using (PixelAccessor firstPassPixels = firstPass.Lock(width, source.Height)) - using (PixelAccessor targetPixels = target.Lock(width, height)) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor firstPassPixels = firstPass.Lock(width, source.Height)) + using (PixelAccessor targetPixels = target.Lock(width, height)) { Parallel.For( 0, diff --git a/src/ImageSharp/Filters/Processors/Transforms/CropProcessor.cs b/src/ImageSharp/Filters/Processors/Transforms/CropProcessor.cs index 6a10e843d..a76897436 100644 --- a/src/ImageSharp/Filters/Processors/Transforms/CropProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Transforms/CropProcessor.cs @@ -12,13 +12,11 @@ namespace ImageSharp.Processors /// Provides methods to allow the cropping of an image. /// /// The pixel format. - /// The packed format. uint, long, float. - public class CropProcessor : ImageFilteringProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class CropProcessor : ImageFilteringProcessor + where TColor : struct, IPackedPixel, IEquatable { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The target cropped rectangle. public CropProcessor(Rectangle cropRectangle) @@ -32,7 +30,7 @@ namespace ImageSharp.Processors public Rectangle CropRectangle { get; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { if (this.CropRectangle == sourceRectangle) { @@ -46,8 +44,8 @@ namespace ImageSharp.Processors TColor[] target = new TColor[this.CropRectangle.Width * this.CropRectangle.Height]; - using (PixelAccessor sourcePixels = source.Lock()) - using (PixelAccessor targetPixels = target.Lock(this.CropRectangle.Width, this.CropRectangle.Height)) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock(this.CropRectangle.Width, this.CropRectangle.Height)) { Parallel.For( minY, diff --git a/src/ImageSharp/Filters/Processors/Transforms/EntropyCropProcessor.cs b/src/ImageSharp/Filters/Processors/Transforms/EntropyCropProcessor.cs index 0415f0585..a8bf373dc 100644 --- a/src/ImageSharp/Filters/Processors/Transforms/EntropyCropProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Transforms/EntropyCropProcessor.cs @@ -12,13 +12,11 @@ namespace ImageSharp.Processors /// entropy. /// /// The pixel format. - /// The packed format. uint, long, float. - public class EntropyCropProcessor : ImageFilteringProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class EntropyCropProcessor : ImageFilteringProcessor + where TColor : struct, IPackedPixel, IEquatable { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The threshold to split the image. Must be between 0 and 1. /// @@ -36,16 +34,16 @@ namespace ImageSharp.Processors public float Value { get; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { - ImageBase temp = new Image(source.Width, source.Height); + ImageBase temp = new Image(source.Width, source.Height); temp.ClonePixels(source.Width, source.Height, source.Pixels); // Detect the edges. - new SobelProcessor().Apply(temp, sourceRectangle); + new SobelProcessor().Apply(temp, sourceRectangle); // Apply threshold binarization filter. - new BinaryThresholdProcessor(this.Value).Apply(temp, sourceRectangle); + new BinaryThresholdProcessor(this.Value).Apply(temp, sourceRectangle); // Search for the first white pixels Rectangle rectangle = ImageMaths.GetFilteredBoundingRectangle(temp, 0); @@ -55,7 +53,7 @@ namespace ImageSharp.Processors return; } - new CropProcessor(rectangle).Apply(source, sourceRectangle); + new CropProcessor(rectangle).Apply(source, sourceRectangle); } } } \ No newline at end of file diff --git a/src/ImageSharp/Filters/Processors/Transforms/FlipProcessor.cs b/src/ImageSharp/Filters/Processors/Transforms/FlipProcessor.cs index 89006275f..aff49327a 100644 --- a/src/ImageSharp/Filters/Processors/Transforms/FlipProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Transforms/FlipProcessor.cs @@ -12,13 +12,11 @@ namespace ImageSharp.Processors /// Provides methods that allow the flipping of an image around its center point. /// /// The pixel format. - /// The packed format. uint, long, float. - public class FlipProcessor : ImageFilteringProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class FlipProcessor : ImageFilteringProcessor + where TColor : struct, IPackedPixel, IEquatable { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The used to perform flipping. public FlipProcessor(FlipType flipType) @@ -32,7 +30,7 @@ namespace ImageSharp.Processors public FlipType FlipType { get; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { switch (this.FlipType) { @@ -51,7 +49,7 @@ namespace ImageSharp.Processors /// at half the height of the image. /// /// The source image to apply the process to. - private void FlipX(ImageBase source) + private void FlipX(ImageBase source) { int width = source.Width; int height = source.Height; @@ -59,8 +57,8 @@ namespace ImageSharp.Processors TColor[] target = new TColor[width * height]; - using (PixelAccessor sourcePixels = source.Lock()) - using (PixelAccessor targetPixels = target.Lock(width, height)) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock(width, height)) { Parallel.For( 0, @@ -85,7 +83,7 @@ namespace ImageSharp.Processors /// at half of the width of the image. /// /// The source image to apply the process to. - private void FlipY(ImageBase source) + private void FlipY(ImageBase source) { int width = source.Width; int height = source.Height; @@ -93,8 +91,8 @@ namespace ImageSharp.Processors TColor[] target = new TColor[width * height]; - using (PixelAccessor sourcePixels = source.Lock()) - using (PixelAccessor targetPixels = target.Lock(width, height)) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock(width, height)) { Parallel.For( 0, diff --git a/src/ImageSharp/Filters/Processors/Transforms/Matrix3x2Processor.cs b/src/ImageSharp/Filters/Processors/Transforms/Matrix3x2Processor.cs index 683277499..c9da4828a 100644 --- a/src/ImageSharp/Filters/Processors/Transforms/Matrix3x2Processor.cs +++ b/src/ImageSharp/Filters/Processors/Transforms/Matrix3x2Processor.cs @@ -12,10 +12,8 @@ namespace ImageSharp.Processors /// Provides methods to transform an image using a . /// /// The pixel format. - /// The packed format. uint, long, float. - public abstract class Matrix3x2Processor : ImageFilteringProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public abstract class Matrix3x2Processor : ImageFilteringProcessor + where TColor : struct, IPackedPixel, IEquatable { /// /// Gets the rectangle designating the target canvas. @@ -43,7 +41,7 @@ namespace ImageSharp.Processors /// /// The . /// - protected Matrix3x2 GetCenteredMatrix(ImageBase source, Matrix3x2 matrix) + protected Matrix3x2 GetCenteredMatrix(ImageBase source, Matrix3x2 matrix) { Matrix3x2 translationToTargetCenter = Matrix3x2.CreateTranslation(-this.CanvasRectangle.Width * .5F, -this.CanvasRectangle.Height * .5F); Matrix3x2 translateToSourceCenter = Matrix3x2.CreateTranslation(source.Width * .5F, source.Height * .5F); diff --git a/src/ImageSharp/Filters/Processors/Transforms/ResamplingWeightedProcessor.cs b/src/ImageSharp/Filters/Processors/Transforms/ResamplingWeightedProcessor.cs index 600267e5a..860485e6d 100644 --- a/src/ImageSharp/Filters/Processors/Transforms/ResamplingWeightedProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Transforms/ResamplingWeightedProcessor.cs @@ -12,13 +12,11 @@ namespace ImageSharp.Processors /// Adapted from /// /// The pixel format. - /// The packed format. uint, long, float. - public abstract class ResamplingWeightedProcessor : ImageFilteringProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public abstract class ResamplingWeightedProcessor : ImageFilteringProcessor + where TColor : struct, IPackedPixel, IEquatable { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The sampler to perform the resize operation. /// The target width. @@ -69,7 +67,7 @@ namespace ImageSharp.Processors protected Weights[] VerticalWeights { get; set; } /// - protected override void BeforeApply(ImageBase source, Rectangle sourceRectangle) + protected override void BeforeApply(ImageBase source, Rectangle sourceRectangle) { if (!(this.Sampler is NearestNeighborResampler)) { diff --git a/src/ImageSharp/Filters/Processors/Transforms/ResizeProcessor.cs b/src/ImageSharp/Filters/Processors/Transforms/ResizeProcessor.cs index 00667214b..48f6b5036 100644 --- a/src/ImageSharp/Filters/Processors/Transforms/ResizeProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Transforms/ResizeProcessor.cs @@ -13,16 +13,14 @@ namespace ImageSharp.Processors /// Provides methods that allow the resizing of images using various algorithms. /// /// - /// This version and the have been separated out to improve performance. + /// This version and the have been separated out to improve performance. /// /// The pixel format. - /// The packed format. uint, long, float. - public class ResizeProcessor : ResamplingWeightedProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class ResizeProcessor : ResamplingWeightedProcessor + where TColor : struct, IPackedPixel, IEquatable { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The sampler to perform the resize operation. /// The target width. @@ -33,7 +31,7 @@ namespace ImageSharp.Processors } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The sampler to perform the resize operation. /// The target width. @@ -47,7 +45,7 @@ namespace ImageSharp.Processors } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { // Jump out, we'll deal with that later. if (source.Width == this.Width && source.Height == this.Height && sourceRectangle == this.ResizeRectangle) @@ -75,8 +73,8 @@ namespace ImageSharp.Processors float widthFactor = sourceRectangle.Width / (float)this.ResizeRectangle.Width; float heightFactor = sourceRectangle.Height / (float)this.ResizeRectangle.Height; - using (PixelAccessor sourcePixels = source.Lock()) - using (PixelAccessor targetPixels = target.Lock(width, height)) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock(width, height)) { Parallel.For( minY, @@ -105,9 +103,9 @@ namespace ImageSharp.Processors // First process the columns. Since we are not using multiple threads startY and endY // are the upper and lower bounds of the source rectangle. TColor[] firstPass = new TColor[width * source.Height]; - using (PixelAccessor sourcePixels = source.Lock()) - using (PixelAccessor firstPassPixels = firstPass.Lock(width, source.Height)) - using (PixelAccessor targetPixels = target.Lock(width, height)) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor firstPassPixels = firstPass.Lock(width, source.Height)) + using (PixelAccessor targetPixels = target.Lock(width, height)) { Parallel.For( 0, diff --git a/src/ImageSharp/Filters/Processors/Transforms/RotateProcessor.cs b/src/ImageSharp/Filters/Processors/Transforms/RotateProcessor.cs index 1f28ded29..33e5b6470 100644 --- a/src/ImageSharp/Filters/Processors/Transforms/RotateProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Transforms/RotateProcessor.cs @@ -13,10 +13,8 @@ namespace ImageSharp.Processors /// Provides methods that allow the rotating of images. /// /// The pixel format. - /// The packed format. uint, long, float. - public class RotateProcessor : Matrix3x2Processor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class RotateProcessor : Matrix3x2Processor + where TColor : struct, IPackedPixel, IEquatable { /// /// The transform matrix to apply. @@ -34,7 +32,7 @@ namespace ImageSharp.Processors public bool Expand { get; set; } = true; /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { if (this.OptimizedApply(source)) { @@ -46,8 +44,8 @@ namespace ImageSharp.Processors Matrix3x2 matrix = this.GetCenteredMatrix(source, this.processMatrix); TColor[] target = new TColor[width * height]; - using (PixelAccessor sourcePixels = source.Lock()) - using (PixelAccessor targetPixels = target.Lock(width, height)) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock(width, height)) { Parallel.For( 0, @@ -70,7 +68,7 @@ namespace ImageSharp.Processors } /// - protected override void BeforeApply(ImageBase source, Rectangle sourceRectangle) + protected override void BeforeApply(ImageBase source, Rectangle sourceRectangle) { const float Epsilon = .0001F; @@ -91,7 +89,7 @@ namespace ImageSharp.Processors /// /// The source image. /// The - private bool OptimizedApply(ImageBase source) + private bool OptimizedApply(ImageBase source) { const float Epsilon = .0001F; if (Math.Abs(this.Angle) < Epsilon) @@ -125,14 +123,14 @@ namespace ImageSharp.Processors /// Rotates the image 270 degrees clockwise at the centre point. /// /// The source image. - private void Rotate270(ImageBase source) + private void Rotate270(ImageBase source) { int width = source.Width; int height = source.Height; TColor[] target = new TColor[width * height]; - using (PixelAccessor sourcePixels = source.Lock()) - using (PixelAccessor targetPixels = target.Lock(height, width)) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock(height, width)) { Parallel.For( 0, @@ -157,14 +155,14 @@ namespace ImageSharp.Processors /// Rotates the image 180 degrees clockwise at the centre point. /// /// The source image. - private void Rotate180(ImageBase source) + private void Rotate180(ImageBase source) { int width = source.Width; int height = source.Height; TColor[] target = new TColor[width * height]; - using (PixelAccessor sourcePixels = source.Lock()) - using (PixelAccessor targetPixels = target.Lock(width, height)) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock(width, height)) { Parallel.For( 0, @@ -188,14 +186,14 @@ namespace ImageSharp.Processors /// Rotates the image 90 degrees clockwise at the centre point. /// /// The source image. - private void Rotate90(ImageBase source) + private void Rotate90(ImageBase source) { int width = source.Width; int height = source.Height; TColor[] target = new TColor[width * height]; - using (PixelAccessor sourcePixels = source.Lock()) - using (PixelAccessor targetPixels = target.Lock(height, width)) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock(height, width)) { Parallel.For( 0, diff --git a/src/ImageSharp/Filters/Processors/Transforms/SkewProcessor.cs b/src/ImageSharp/Filters/Processors/Transforms/SkewProcessor.cs index b8f8d3afd..e13d4995b 100644 --- a/src/ImageSharp/Filters/Processors/Transforms/SkewProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Transforms/SkewProcessor.cs @@ -13,10 +13,8 @@ namespace ImageSharp.Processors /// Provides methods that allow the skewing of images. /// /// The pixel format. - /// The packed format. uint, long, float. - public class SkewProcessor : Matrix3x2Processor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class SkewProcessor : Matrix3x2Processor + where TColor : struct, IPackedPixel, IEquatable { /// /// The transform matrix to apply. @@ -39,15 +37,15 @@ namespace ImageSharp.Processors public bool Expand { get; set; } = true; /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { int height = this.CanvasRectangle.Height; int width = this.CanvasRectangle.Width; Matrix3x2 matrix = this.GetCenteredMatrix(source, this.processMatrix); TColor[] target = new TColor[width * height]; - using (PixelAccessor sourcePixels = source.Lock()) - using (PixelAccessor targetPixels = target.Lock(width, height)) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock(width, height)) { Parallel.For( 0, @@ -70,7 +68,7 @@ namespace ImageSharp.Processors } /// - protected override void BeforeApply(ImageBase source, Rectangle sourceRectangle) + protected override void BeforeApply(ImageBase source, Rectangle sourceRectangle) { this.processMatrix = Point.CreateSkew(new Point(0, 0), -this.AngleX, -this.AngleY); if (this.Expand) diff --git a/src/ImageSharp/Filters/Transforms/AutoOrient.cs b/src/ImageSharp/Filters/Transforms/AutoOrient.cs index a30dec9b5..cdd62624a 100644 --- a/src/ImageSharp/Filters/Transforms/AutoOrient.cs +++ b/src/ImageSharp/Filters/Transforms/AutoOrient.cs @@ -8,7 +8,7 @@ namespace ImageSharp using System; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -16,12 +16,10 @@ namespace ImageSharp /// Adjusts an image so that its orientation is suitable for viewing. Adjustments are based on EXIF metadata embedded in the image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image to auto rotate. /// The - public static Image AutoOrient(this Image source) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image AutoOrient(this Image source) + where TColor : struct, IPackedPixel, IEquatable { Orientation orientation = GetExifOrientation(source); @@ -61,12 +59,10 @@ namespace ImageSharp /// Returns the current EXIF orientation /// /// The pixel format. - /// The packed format. uint, long, float. /// The image to auto rotate. /// The - private static Orientation GetExifOrientation(Image source) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private static Orientation GetExifOrientation(Image source) + where TColor : struct, IPackedPixel, IEquatable { if (source.ExifProfile == null) { diff --git a/src/ImageSharp/Filters/Transforms/Crop.cs b/src/ImageSharp/Filters/Transforms/Crop.cs index 0ffadc94d..8b5ad7daf 100644 --- a/src/ImageSharp/Filters/Transforms/Crop.cs +++ b/src/ImageSharp/Filters/Transforms/Crop.cs @@ -10,7 +10,7 @@ namespace ImageSharp using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -18,14 +18,12 @@ namespace ImageSharp /// Crops an image to the given width and height. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image to resize. /// The target image width. /// The target image height. - /// The - public static Image Crop(this Image source, int width, int height) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The + public static Image Crop(this Image source, int width, int height) + where TColor : struct, IPackedPixel, IEquatable { return Crop(source, new Rectangle(0, 0, width, height)); } @@ -34,17 +32,15 @@ namespace ImageSharp /// Crops an image to the given rectangle. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image to crop. /// /// The structure that specifies the portion of the image object to retain. /// /// The - public static Image Crop(this Image source, Rectangle cropRectangle) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image Crop(this Image source, Rectangle cropRectangle) + where TColor : struct, IPackedPixel, IEquatable { - CropProcessor processor = new CropProcessor(cropRectangle); + CropProcessor processor = new CropProcessor(cropRectangle); return source.Process(source.Bounds, processor); } } diff --git a/src/ImageSharp/Filters/Transforms/EntropyCrop.cs b/src/ImageSharp/Filters/Transforms/EntropyCrop.cs index ce4c8096d..a2abcf38d 100644 --- a/src/ImageSharp/Filters/Transforms/EntropyCrop.cs +++ b/src/ImageSharp/Filters/Transforms/EntropyCrop.cs @@ -10,7 +10,7 @@ namespace ImageSharp using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -18,15 +18,13 @@ namespace ImageSharp /// Crops an image to the area of greatest entropy. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image to crop. /// The threshold for entropic density. /// The - public static Image EntropyCrop(this Image source, float threshold = .5f) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image EntropyCrop(this Image source, float threshold = .5f) + where TColor : struct, IPackedPixel, IEquatable { - EntropyCropProcessor processor = new EntropyCropProcessor(threshold); + EntropyCropProcessor processor = new EntropyCropProcessor(threshold); return source.Process(source.Bounds, processor); } } diff --git a/src/ImageSharp/Filters/Transforms/Flip.cs b/src/ImageSharp/Filters/Transforms/Flip.cs index c42aef81e..6feb726b4 100644 --- a/src/ImageSharp/Filters/Transforms/Flip.cs +++ b/src/ImageSharp/Filters/Transforms/Flip.cs @@ -10,7 +10,7 @@ namespace ImageSharp using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -18,15 +18,13 @@ namespace ImageSharp /// Flips an image by the given instructions. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image to rotate, flip, or both. /// The to perform the flip. /// The - public static Image Flip(this Image source, FlipType flipType) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image Flip(this Image source, FlipType flipType) + where TColor : struct, IPackedPixel, IEquatable { - FlipProcessor processor = new FlipProcessor(flipType); + FlipProcessor processor = new FlipProcessor(flipType); return source.Process(source.Bounds, processor); } } diff --git a/src/ImageSharp/Filters/Transforms/Options/ResizeHelper.cs b/src/ImageSharp/Filters/Transforms/Options/ResizeHelper.cs index 002831c58..97a88115e 100644 --- a/src/ImageSharp/Filters/Transforms/Options/ResizeHelper.cs +++ b/src/ImageSharp/Filters/Transforms/Options/ResizeHelper.cs @@ -18,15 +18,13 @@ namespace ImageSharp /// Calculates the target location and bounds to perform the resize operation against. /// /// The pixel format. - /// The packed format. uint, long, float. /// The source image. /// The resize options. /// /// The . /// - public static Rectangle CalculateTargetLocationAndBounds(ImageBase source, ResizeOptions options) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Rectangle CalculateTargetLocationAndBounds(ImageBase source, ResizeOptions options) + where TColor : struct, IPackedPixel, IEquatable { switch (options.Mode) { @@ -51,15 +49,13 @@ namespace ImageSharp /// Calculates the target rectangle for crop mode. /// /// The pixel format. - /// The packed format. uint, long, float. /// The source image. /// The resize options. /// /// The . /// - private static Rectangle CalculateCropRectangle(ImageBase source, ResizeOptions options) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private static Rectangle CalculateCropRectangle(ImageBase source, ResizeOptions options) + where TColor : struct, IPackedPixel, IEquatable { int width = options.Size.Width; int height = options.Size.Height; @@ -172,15 +168,13 @@ namespace ImageSharp /// Calculates the target rectangle for pad mode. /// /// The pixel format. - /// The packed format. uint, long, float. /// The source image. /// The resize options. /// /// The . /// - private static Rectangle CalculatePadRectangle(ImageBase source, ResizeOptions options) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private static Rectangle CalculatePadRectangle(ImageBase source, ResizeOptions options) + where TColor : struct, IPackedPixel, IEquatable { int width = options.Size.Width; int height = options.Size.Height; @@ -255,15 +249,13 @@ namespace ImageSharp /// Calculates the target rectangle for box pad mode. /// /// The pixel format. - /// The packed format. uint, long, float. /// The source image. /// The resize options. /// /// The . /// - private static Rectangle CalculateBoxPadRectangle(ImageBase source, ResizeOptions options) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private static Rectangle CalculateBoxPadRectangle(ImageBase source, ResizeOptions options) + where TColor : struct, IPackedPixel, IEquatable { int width = options.Size.Width; int height = options.Size.Height; @@ -344,15 +336,13 @@ namespace ImageSharp /// Calculates the target rectangle for max mode. /// /// The pixel format. - /// The packed format. uint, long, float. /// The source image. /// The resize options. /// /// The . /// - private static Rectangle CalculateMaxRectangle(ImageBase source, ResizeOptions options) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private static Rectangle CalculateMaxRectangle(ImageBase source, ResizeOptions options) + where TColor : struct, IPackedPixel, IEquatable { int width = options.Size.Width; int height = options.Size.Height; @@ -387,15 +377,13 @@ namespace ImageSharp /// Calculates the target rectangle for min mode. /// /// The pixel format. - /// The packed format. uint, long, float. /// The source image. /// The resize options. /// /// The . /// - private static Rectangle CalculateMinRectangle(ImageBase source, ResizeOptions options) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private static Rectangle CalculateMinRectangle(ImageBase source, ResizeOptions options) + where TColor : struct, IPackedPixel, IEquatable { int width = options.Size.Width; int height = options.Size.Height; diff --git a/src/ImageSharp/Filters/Transforms/Pad.cs b/src/ImageSharp/Filters/Transforms/Pad.cs index 731304279..265edd23d 100644 --- a/src/ImageSharp/Filters/Transforms/Pad.cs +++ b/src/ImageSharp/Filters/Transforms/Pad.cs @@ -8,7 +8,7 @@ namespace ImageSharp using System; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -16,14 +16,12 @@ namespace ImageSharp /// Evenly pads an image to fit the new dimensions. /// /// The pixel format. - /// The packed format. uint, long, float. /// The source image to pad. /// The new width. /// The new height. - /// The . - public static Image Pad(this Image source, int width, int height) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image Pad(this Image source, int width, int height) + where TColor : struct, IPackedPixel, IEquatable { ResizeOptions options = new ResizeOptions { diff --git a/src/ImageSharp/Filters/Transforms/Resize.cs b/src/ImageSharp/Filters/Transforms/Resize.cs index 0eaf89930..f1e62df8e 100644 --- a/src/ImageSharp/Filters/Transforms/Resize.cs +++ b/src/ImageSharp/Filters/Transforms/Resize.cs @@ -10,7 +10,7 @@ namespace ImageSharp using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -18,14 +18,12 @@ namespace ImageSharp /// Resizes an image in accordance with the given . /// /// The pixel format. - /// The packed format. uint, long, float. /// The image to resize. /// The resize options. - /// The + /// The /// Passing zero for one of height or width within the resize options will automatically preserve the aspect ratio of the original image - public static Image Resize(this Image source, ResizeOptions options) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image Resize(this Image source, ResizeOptions options) + where TColor : struct, IPackedPixel, IEquatable { // Ensure size is populated across both dimensions. if (options.Size.Width == 0 && options.Size.Height > 0) @@ -47,15 +45,13 @@ namespace ImageSharp /// Resizes an image to the given width and height. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image to resize. /// The target image width. /// The target image height. - /// The + /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static Image Resize(this Image source, int width, int height) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image Resize(this Image source, int width, int height) + where TColor : struct, IPackedPixel, IEquatable { return Resize(source, width, height, new BicubicResampler(), false); } @@ -64,16 +60,14 @@ namespace ImageSharp /// Resizes an image to the given width and height. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image to resize. /// The target image width. /// The target image height. /// Whether to compress and expand the image color-space to gamma correct the image during processing. - /// The + /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static Image Resize(this Image source, int width, int height, bool compand) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image Resize(this Image source, int width, int height, bool compand) + where TColor : struct, IPackedPixel, IEquatable { return Resize(source, width, height, new BicubicResampler(), compand); } @@ -82,16 +76,14 @@ namespace ImageSharp /// Resizes an image to the given width and height with the given sampler. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image to resize. /// The target image width. /// The target image height. /// The to perform the resampling. - /// The + /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static Image Resize(this Image source, int width, int height, IResampler sampler) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image Resize(this Image source, int width, int height, IResampler sampler) + where TColor : struct, IPackedPixel, IEquatable { return Resize(source, width, height, sampler, false); } @@ -100,17 +92,15 @@ namespace ImageSharp /// Resizes an image to the given width and height with the given sampler. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image to resize. /// The target image width. /// The target image height. /// The to perform the resampling. /// Whether to compress and expand the image color-space to gamma correct the image during processing. - /// The + /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static Image Resize(this Image source, int width, int height, IResampler sampler, bool compand) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image Resize(this Image source, int width, int height, IResampler sampler, bool compand) + where TColor : struct, IPackedPixel, IEquatable { return Resize(source, width, height, sampler, source.Bounds, new Rectangle(0, 0, width, height), compand); } @@ -120,7 +110,6 @@ namespace ImageSharp /// source rectangle. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image to resize. /// The target image width. /// The target image height. @@ -132,11 +121,10 @@ namespace ImageSharp /// The structure that specifies the portion of the target image object to draw to. /// /// Whether to compress and expand the image color-space to gamma correct the image during processing. - /// The + /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static Image Resize(this Image source, int width, int height, IResampler sampler, Rectangle sourceRectangle, Rectangle targetRectangle, bool compand = false) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image Resize(this Image source, int width, int height, IResampler sampler, Rectangle sourceRectangle, Rectangle targetRectangle, bool compand = false) + where TColor : struct, IPackedPixel, IEquatable { if (width == 0 && height > 0) { @@ -153,15 +141,15 @@ namespace ImageSharp Guard.MustBeGreaterThan(width, 0, nameof(width)); Guard.MustBeGreaterThan(height, 0, nameof(height)); - ResamplingWeightedProcessor processor; + ResamplingWeightedProcessor processor; if (compand) { - processor = new CompandingResizeProcessor(sampler, width, height, targetRectangle); + processor = new CompandingResizeProcessor(sampler, width, height, targetRectangle); } else { - processor = new ResizeProcessor(sampler, width, height, targetRectangle); + processor = new ResizeProcessor(sampler, width, height, targetRectangle); } return source.Process(sourceRectangle, processor); diff --git a/src/ImageSharp/Filters/Transforms/Rotate.cs b/src/ImageSharp/Filters/Transforms/Rotate.cs index b53e79a25..3d88523c6 100644 --- a/src/ImageSharp/Filters/Transforms/Rotate.cs +++ b/src/ImageSharp/Filters/Transforms/Rotate.cs @@ -10,7 +10,7 @@ namespace ImageSharp using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -18,13 +18,11 @@ namespace ImageSharp /// Rotates an image by the given angle in degrees, expanding the image to fit the rotated result. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image to rotate. /// The angle in degrees to perform the rotation. /// The - public static Image Rotate(this Image source, float degrees) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image Rotate(this Image source, float degrees) + where TColor : struct, IPackedPixel, IEquatable { return Rotate(source, degrees, true); } @@ -33,13 +31,11 @@ namespace ImageSharp /// Rotates and flips an image by the given instructions. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image to rotate. /// The to perform the rotation. /// The - public static Image Rotate(this Image source, RotateType rotateType) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image Rotate(this Image source, RotateType rotateType) + where TColor : struct, IPackedPixel, IEquatable { return Rotate(source, (float)rotateType, false); } @@ -48,16 +44,14 @@ namespace ImageSharp /// Rotates an image by the given angle in degrees. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image to rotate. /// The angle in degrees to perform the rotation. /// Whether to expand the image to fit the rotated result. /// The - public static Image Rotate(this Image source, float degrees, bool expand) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image Rotate(this Image source, float degrees, bool expand) + where TColor : struct, IPackedPixel, IEquatable { - RotateProcessor processor = new RotateProcessor { Angle = degrees, Expand = expand }; + RotateProcessor processor = new RotateProcessor { Angle = degrees, Expand = expand }; return source.Process(source.Bounds, processor); } } diff --git a/src/ImageSharp/Filters/Transforms/RotateFlip.cs b/src/ImageSharp/Filters/Transforms/RotateFlip.cs index 8a3097985..02eb7b702 100644 --- a/src/ImageSharp/Filters/Transforms/RotateFlip.cs +++ b/src/ImageSharp/Filters/Transforms/RotateFlip.cs @@ -8,7 +8,7 @@ namespace ImageSharp using System; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -16,14 +16,12 @@ namespace ImageSharp /// Rotates and flips an image by the given instructions. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image to rotate, flip, or both. /// The to perform the rotation. /// The to perform the flip. /// The - public static Image RotateFlip(this Image source, RotateType rotateType, FlipType flipType) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image RotateFlip(this Image source, RotateType rotateType, FlipType flipType) + where TColor : struct, IPackedPixel, IEquatable { return source.Rotate(rotateType).Flip(flipType); } diff --git a/src/ImageSharp/Filters/Transforms/Skew.cs b/src/ImageSharp/Filters/Transforms/Skew.cs index 664c9e31f..dab0ace2f 100644 --- a/src/ImageSharp/Filters/Transforms/Skew.cs +++ b/src/ImageSharp/Filters/Transforms/Skew.cs @@ -10,7 +10,7 @@ namespace ImageSharp using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -18,14 +18,12 @@ namespace ImageSharp /// Skews an image by the given angles in degrees, expanding the image to fit the skewed result. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image to skew. /// The angle in degrees to perform the rotation along the x-axis. /// The angle in degrees to perform the rotation along the y-axis. /// The - public static Image Skew(this Image source, float degreesX, float degreesY) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image Skew(this Image source, float degreesX, float degreesY) + where TColor : struct, IPackedPixel, IEquatable { return Skew(source, degreesX, degreesY, true); } @@ -34,17 +32,15 @@ namespace ImageSharp /// Skews an image by the given angles in degrees. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image to skew. /// The angle in degrees to perform the rotation along the x-axis. /// The angle in degrees to perform the rotation along the y-axis. /// Whether to expand the image to fit the skewed result. /// The - public static Image Skew(this Image source, float degreesX, float degreesY, bool expand) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public static Image Skew(this Image source, float degreesX, float degreesY, bool expand) + where TColor : struct, IPackedPixel, IEquatable { - SkewProcessor processor = new SkewProcessor { AngleX = degreesX, AngleY = degreesY, Expand = expand }; + SkewProcessor processor = new SkewProcessor { AngleX = degreesX, AngleY = degreesY, Expand = expand }; return source.Process(source.Bounds, processor); } } diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoder.cs b/src/ImageSharp/Formats/Bmp/BmpDecoder.cs index 929a29b0b..ae7e6c72a 100644 --- a/src/ImageSharp/Formats/Bmp/BmpDecoder.cs +++ b/src/ImageSharp/Formats/Bmp/BmpDecoder.cs @@ -26,10 +26,9 @@ namespace ImageSharp.Formats public class BmpDecoder : IImageDecoder { /// - public void Decode(Image image, Stream stream) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable - { + public void Decode(Image image, Stream stream) + where TColor : struct, IPackedPixel, IEquatable + { Guard.NotNull(image, "image"); Guard.NotNull(stream, "stream"); diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs index 918eaac4c..981d6c097 100644 --- a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs @@ -48,7 +48,6 @@ namespace ImageSharp.Formats /// the data to image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image, where the data should be set to. /// Cannot be null (Nothing in Visual Basic). /// The stream, where the image should be @@ -58,9 +57,8 @@ namespace ImageSharp.Formats /// - or - /// is null. /// - public void Decode(Image image, Stream stream) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public void Decode(Image image, Stream stream) + where TColor : struct, IPackedPixel, IEquatable { this.currentStream = stream; @@ -121,7 +119,7 @@ namespace ImageSharp.Formats image.InitPixels(this.infoHeader.Width, this.infoHeader.Height); - using (PixelAccessor pixels = image.Lock()) + using (PixelAccessor pixels = image.Lock()) { switch (this.infoHeader.Compression) { @@ -207,16 +205,14 @@ namespace ImageSharp.Formats /// Reads the color palette from the stream. /// /// The pixel format. - /// The packed format. uint, long, float. - /// The to assign the palette to. + /// The to assign the palette to. /// The containing the colors. /// The width of the bitmap. /// The height of the bitmap. /// The number of bits per pixel. /// Whether the bitmap is inverted. - private void ReadRgbPalette(PixelAccessor pixels, byte[] colors, int width, int height, int bits, bool inverted) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private void ReadRgbPalette(PixelAccessor pixels, byte[] colors, int width, int height, int bits, bool inverted) + where TColor : struct, IPackedPixel, IEquatable { // Pixels per byte (bits per pixel) int ppb = 8 / bits; @@ -266,14 +262,12 @@ namespace ImageSharp.Formats /// Reads the 16 bit color palette from the stream /// /// The pixel format. - /// The packed format. uint, long, float. - /// The to assign the palette to. + /// The to assign the palette to. /// The width of the bitmap. /// The height of the bitmap. /// Whether the bitmap is inverted. - private void ReadRgb16(PixelAccessor pixels, int width, int height, bool inverted) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private void ReadRgb16(PixelAccessor pixels, int width, int height, bool inverted) + where TColor : struct, IPackedPixel, IEquatable { // We divide here as we will store the colors in our floating point format. const int ScaleR = 8; // 256/32 @@ -281,7 +275,7 @@ namespace ImageSharp.Formats const int ComponentCount = 2; TColor color = default(TColor); - using (PixelArea row = new PixelArea(width, ComponentOrder.XYZ)) + using (PixelArea row = new PixelArea(width, ComponentOrder.XYZ)) { for (int y = 0; y < height; y++) { @@ -310,17 +304,15 @@ namespace ImageSharp.Formats /// Reads the 24 bit color palette from the stream /// /// The pixel format. - /// The packed format. uint, long, float. - /// The to assign the palette to. + /// The to assign the palette to. /// The width of the bitmap. /// The height of the bitmap. /// Whether the bitmap is inverted. - private void ReadRgb24(PixelAccessor pixels, int width, int height, bool inverted) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private void ReadRgb24(PixelAccessor pixels, int width, int height, bool inverted) + where TColor : struct, IPackedPixel, IEquatable { int padding = CalculatePadding(width, 3); - using (PixelArea row = new PixelArea(width, ComponentOrder.ZYX, padding)) + using (PixelArea row = new PixelArea(width, ComponentOrder.ZYX, padding)) { for (int y = 0; y < height; y++) { @@ -336,17 +328,15 @@ namespace ImageSharp.Formats /// Reads the 32 bit color palette from the stream /// /// The pixel format. - /// The packed format. uint, long, float. - /// The to assign the palette to. + /// The to assign the palette to. /// The width of the bitmap. /// The height of the bitmap. /// Whether the bitmap is inverted. - private void ReadRgb32(PixelAccessor pixels, int width, int height, bool inverted) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private void ReadRgb32(PixelAccessor pixels, int width, int height, bool inverted) + where TColor : struct, IPackedPixel, IEquatable { int padding = CalculatePadding(width, 4); - using (PixelArea row = new PixelArea(width, ComponentOrder.ZYXW, padding)) + using (PixelArea row = new PixelArea(width, ComponentOrder.ZYXW, padding)) { for (int y = 0; y < height; y++) { diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoder.cs b/src/ImageSharp/Formats/Bmp/BmpEncoder.cs index d0483fc03..2ed6b3b98 100644 --- a/src/ImageSharp/Formats/Bmp/BmpEncoder.cs +++ b/src/ImageSharp/Formats/Bmp/BmpEncoder.cs @@ -20,10 +20,9 @@ namespace ImageSharp.Formats public BmpBitsPerPixel BitsPerPixel { get; set; } = BmpBitsPerPixel.Pixel24; /// - public void Encode(Image image, Stream stream) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable - { + public void Encode(Image image, Stream stream) + where TColor : struct, IPackedPixel, IEquatable + { BmpEncoderCore encoder = new BmpEncoderCore(); encoder.Encode(image, stream, this.BitsPerPixel); } diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs index 0dd5755b4..8b7d79156 100644 --- a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs @@ -26,17 +26,15 @@ namespace ImageSharp.Formats private int padding; /// - /// Encodes the image to the specified stream from the . + /// Encodes the image to the specified stream from the . /// /// The pixel format. - /// The packed format. long, float. - /// The to encode from. + /// The to encode from. /// The to encode the image data to. /// The - public void Encode(ImageBase image, Stream stream, BmpBitsPerPixel bitsPerPixel) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable - { + public void Encode(ImageBase image, Stream stream, BmpBitsPerPixel bitsPerPixel) + where TColor : struct, IPackedPixel, IEquatable + { Guard.NotNull(image, nameof(image)); Guard.NotNull(stream, nameof(stream)); @@ -121,25 +119,23 @@ namespace ImageSharp.Formats /// Writes the pixel data to the binary stream. /// /// The pixel format. - /// The packed format. uint, long, float. - /// The containing the stream to write to. + /// The containing the stream to write to. /// - /// The containing pixel data. + /// The containing pixel data. /// - private void WriteImage(EndianBinaryWriter writer, ImageBase image) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable - { - using (PixelAccessor pixels = image.Lock()) + private void WriteImage(EndianBinaryWriter writer, ImageBase image) + where TColor : struct, IPackedPixel, IEquatable + { + using (PixelAccessor pixels = image.Lock()) { switch (this.bmpBitsPerPixel) { case BmpBitsPerPixel.Pixel32: - this.Write32Bit(writer, pixels); + this.Write32Bit(writer, pixels); break; case BmpBitsPerPixel.Pixel24: - this.Write24Bit(writer, pixels); + this.Write24Bit(writer, pixels); break; } } @@ -149,14 +145,12 @@ namespace ImageSharp.Formats /// Writes the 32bit color palette to the stream. /// /// The pixel format. - /// The packed format. uint, long, float. - /// The containing the stream to write to. - /// The containing pixel data. - private void Write32Bit(EndianBinaryWriter writer, PixelAccessor pixels) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable - { - using (PixelArea row = new PixelArea(pixels.Width, ComponentOrder.ZYXW, this.padding)) + /// The containing the stream to write to. + /// The containing pixel data. + private void Write32Bit(EndianBinaryWriter writer, PixelAccessor pixels) + where TColor : struct, IPackedPixel, IEquatable + { + using (PixelArea row = new PixelArea(pixels.Width, ComponentOrder.ZYXW, this.padding)) { for (int y = pixels.Height - 1; y >= 0; y--) { @@ -170,14 +164,12 @@ namespace ImageSharp.Formats /// Writes the 24bit color palette to the stream. /// /// The pixel format. - /// The packed format. uint, long, float. - /// The containing the stream to write to. - /// The containing pixel data. - private void Write24Bit(EndianBinaryWriter writer, PixelAccessor pixels) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable - { - using (PixelArea row = new PixelArea(pixels.Width, ComponentOrder.ZYX, this.padding)) + /// The containing the stream to write to. + /// The containing pixel data. + private void Write24Bit(EndianBinaryWriter writer, PixelAccessor pixels) + where TColor : struct, IPackedPixel, IEquatable + { + using (PixelArea row = new PixelArea(pixels.Width, ComponentOrder.ZYX, this.padding)) { for (int y = pixels.Height - 1; y >= 0; y--) { diff --git a/src/ImageSharp/Formats/Gif/GifDecoder.cs b/src/ImageSharp/Formats/Gif/GifDecoder.cs index 3ed8317d3..ce8c0c06e 100644 --- a/src/ImageSharp/Formats/Gif/GifDecoder.cs +++ b/src/ImageSharp/Formats/Gif/GifDecoder.cs @@ -14,11 +14,10 @@ namespace ImageSharp.Formats public class GifDecoder : IImageDecoder { /// - public void Decode(Image image, Stream stream) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable - { - new GifDecoderCore().Decode(image, stream); + public void Decode(Image image, Stream stream) + where TColor : struct, IPackedPixel, IEquatable + { + new GifDecoderCore().Decode(image, stream); } } } diff --git a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs index d77ce9900..251912c79 100644 --- a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs @@ -13,10 +13,8 @@ namespace ImageSharp.Formats /// Performs the gif decoding operation. /// /// The pixel format. - /// The packed format. uint, long, float. - internal class GifDecoderCore - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + internal class GifDecoderCore + where TColor : struct, IPackedPixel, IEquatable { /// /// The temp buffer used to reduce allocations. @@ -26,7 +24,7 @@ namespace ImageSharp.Formats /// /// The image to decode the information to. /// - private Image decodedImage; + private Image decodedImage; /// /// The currently loaded stream. @@ -44,9 +42,14 @@ namespace ImageSharp.Formats private int globalColorTableLength; /// - /// The current frame. + /// The next frame. /// - private TColor[] currentFrame; + private ImageFrame nextFrame; + + /// + /// The area to restore. + /// + private Rectangle? restoreArea; /// /// The logical screen descriptor. @@ -63,11 +66,12 @@ namespace ImageSharp.Formats /// /// The image to decode to. /// The stream containing image data. - public void Decode(Image image, Stream stream) + public void Decode(Image image, Stream stream) { try { this.decodedImage = image; + this.currentStream = stream; // Skip the identifier @@ -304,28 +308,46 @@ namespace ImageSharp.Formats /// The color table containing the available colors. /// The color table length. /// The - private void ReadFrameColors(byte[] indices, byte[] colorTable, int colorTableLength, GifImageDescriptor descriptor) + private unsafe void ReadFrameColors(byte[] indices, byte[] colorTable, int colorTableLength, GifImageDescriptor descriptor) { int imageWidth = this.logicalScreenDescriptor.Width; int imageHeight = this.logicalScreenDescriptor.Height; - if (this.currentFrame == null) - { - this.currentFrame = new TColor[imageWidth * imageHeight]; - } + ImageFrame previousFrame = null; - TColor[] lastFrame = null; + ImageFrame currentFrame = null; - if (this.graphicsControlExtension != null - && this.graphicsControlExtension.DisposalMethod == DisposalMethod.RestoreToPrevious) + ImageBase image; + + if (this.nextFrame == null) { - lastFrame = new TColor[imageWidth * imageHeight]; + image = this.decodedImage; + + image.Quality = colorTableLength / 3; - using (PixelAccessor lastPixels = lastFrame.Lock(imageWidth, imageHeight)) - using (PixelAccessor currentPixels = this.currentFrame.Lock(imageWidth, imageHeight)) + // This initializes the image to become fully transparent because the alpha channel is zero. + image.InitPixels(imageWidth, imageHeight); + } + else + { + if (this.graphicsControlExtension != null && + this.graphicsControlExtension.DisposalMethod == DisposalMethod.RestoreToPrevious) { - currentPixels.CopyImage(lastPixels); + previousFrame = this.nextFrame; } + + currentFrame = this.nextFrame.Clone(); + + image = currentFrame; + + this.RestoreToBackground(image); + + this.decodedImage.Frames.Add(currentFrame); + } + + if (this.graphicsControlExtension != null && this.graphicsControlExtension.DelayTime > 0) + { + image.FrameDelay = this.graphicsControlExtension.DelayTime; } int i = 0; @@ -333,119 +355,130 @@ namespace ImageSharp.Formats int interlaceIncrement = 8; // The interlacing line increment int interlaceY = 0; // The current interlaced line - // Lock the current image pixels for fast acces. - using (PixelAccessor currentPixels = this.currentFrame.Lock(imageWidth, imageHeight)) + using (PixelAccessor pixelAccessor = image.Lock()) { - for (int y = descriptor.Top; y < descriptor.Top + descriptor.Height; y++) + using (PixelArea pixelRow = new PixelArea(imageWidth, ComponentOrder.XYZW)) { - // Check if this image is interlaced. - int writeY; // the target y offset to write to - if (descriptor.InterlaceFlag) + for (int y = descriptor.Top; y < descriptor.Top + descriptor.Height; y++) { - // If so then we read lines at predetermined offsets. - // When an entire image height worth of offset lines has been read we consider this a pass. - // With each pass the number of offset lines changes and the starting line changes. - if (interlaceY >= descriptor.Height) + // Check if this image is interlaced. + int writeY; // the target y offset to write to + if (descriptor.InterlaceFlag) { - interlacePass++; - switch (interlacePass) + // If so then we read lines at predetermined offsets. + // When an entire image height worth of offset lines has been read we consider this a pass. + // With each pass the number of offset lines changes and the starting line changes. + if (interlaceY >= descriptor.Height) { - case 1: - interlaceY = 4; - break; - case 2: - interlaceY = 2; - interlaceIncrement = 4; - break; - case 3: - interlaceY = 1; - interlaceIncrement = 2; - break; + interlacePass++; + switch (interlacePass) + { + case 1: + interlaceY = 4; + break; + case 2: + interlaceY = 2; + interlaceIncrement = 4; + break; + case 3: + interlaceY = 1; + interlaceIncrement = 2; + break; + } } - } - writeY = interlaceY + descriptor.Top; + writeY = interlaceY + descriptor.Top; - interlaceY += interlaceIncrement; - } - else - { - writeY = y; - } + interlaceY += interlaceIncrement; + } + else + { + writeY = y; + } - for (int x = descriptor.Left; x < descriptor.Left + descriptor.Width; x++) - { - int index = indices[i]; + pixelAccessor.CopyTo(pixelRow, writeY, descriptor.Left); - if (this.graphicsControlExtension == null - || this.graphicsControlExtension.TransparencyFlag == false - || this.graphicsControlExtension.TransparencyIndex != index) + byte* pixelBase = pixelRow.PixelBase; + for (int x = 0; x < descriptor.Width; x++) { - // Stored in r-> g-> b-> a order. - int indexOffset = index * 3; - TColor pixel = default(TColor); - pixel.PackFromBytes(colorTable[indexOffset], colorTable[indexOffset + 1], colorTable[indexOffset + 2], 255); - currentPixels[x, writeY] = pixel; + int index = indices[i]; + + if (this.graphicsControlExtension == null || + this.graphicsControlExtension.TransparencyFlag == false || + this.graphicsControlExtension.TransparencyIndex != index) + { + int indexOffset = index * 3; + *(pixelBase + 0) = colorTable[indexOffset]; + *(pixelBase + 1) = colorTable[indexOffset + 1]; + *(pixelBase + 2) = colorTable[indexOffset + 2]; + *(pixelBase + 3) = 255; + + // TODO: This is actually 200us faster in benchmarking. + // int indexOffset = index * 3; + // TColor pixel = default(TColor); + // pixel.PackFromBytes(colorTable[indexOffset], colorTable[indexOffset + 1], colorTable[indexOffset + 2], 255); + // currentPixels[x, writeY] = pixel; + } + + i++; + pixelBase += 4; } - i++; + pixelAccessor.CopyFrom(pixelRow, writeY, descriptor.Left); } } + } - TColor[] pixels = new TColor[imageWidth * imageHeight]; + if (previousFrame != null) + { + this.nextFrame = previousFrame; + return; + } - using (PixelAccessor newPixels = pixels.Lock(imageWidth, imageHeight)) - { - currentPixels.CopyImage(newPixels); - } + this.nextFrame = currentFrame == null ? this.decodedImage.ToFrame() : currentFrame.Clone(); - ImageBase currentImage; + if (this.graphicsControlExtension != null && + this.graphicsControlExtension.DisposalMethod == DisposalMethod.RestoreToBackground) + { + this.restoreArea = new Rectangle(descriptor.Left, descriptor.Top, descriptor.Width, descriptor.Height); + } + } - if (this.decodedImage.Pixels == null) - { - currentImage = this.decodedImage; - currentImage.SetPixels(imageWidth, imageHeight, pixels); - currentImage.Quality = colorTableLength / 3; + /// + /// Restores the current frame area to the background. + /// + /// The frame. + private void RestoreToBackground(ImageBase frame) + { + if (this.restoreArea == null) + { + return; + } - if (this.graphicsControlExtension != null && this.graphicsControlExtension.DelayTime > 0) - { - this.decodedImage.FrameDelay = this.graphicsControlExtension.DelayTime; - } - } - else + // Optimization for when the size of the frame is the same as the image size. + if (this.restoreArea.Value.Width == this.decodedImage.Width && + this.restoreArea.Value.Height == this.decodedImage.Height) + { + using (PixelAccessor pixelAccessor = frame.Lock()) { - ImageFrame frame = new ImageFrame(); - - currentImage = frame; - currentImage.SetPixels(imageWidth, imageHeight, pixels); - currentImage.Quality = colorTableLength / 3; - - if (this.graphicsControlExtension != null && this.graphicsControlExtension.DelayTime > 0) - { - currentImage.FrameDelay = this.graphicsControlExtension.DelayTime; - } - - this.decodedImage.Frames.Add(frame); + pixelAccessor.Reset(); } - - if (this.graphicsControlExtension != null) + } + else + { + using (PixelArea emptyRow = new PixelArea(this.restoreArea.Value.Width, ComponentOrder.XYZW)) { - if (this.graphicsControlExtension.DisposalMethod == DisposalMethod.RestoreToBackground) + using (PixelAccessor pixelAccessor = frame.Lock()) { - for (int y = descriptor.Top; y < descriptor.Top + descriptor.Height; y++) + for (int y = this.restoreArea.Value.Top; y < this.restoreArea.Value.Top + this.restoreArea.Value.Height; y++) { - for (int x = descriptor.Left; x < descriptor.Left + descriptor.Width; x++) - { - currentPixels[x, y] = default(TColor); - } + pixelAccessor.CopyFrom(emptyRow, y, this.restoreArea.Value.Left); } } - else if (this.graphicsControlExtension.DisposalMethod == DisposalMethod.RestoreToPrevious) - { - this.currentFrame = lastFrame; - } } - } // End lock + } + + this.restoreArea = null; } } } \ No newline at end of file diff --git a/src/ImageSharp/Formats/Gif/GifEncoder.cs b/src/ImageSharp/Formats/Gif/GifEncoder.cs index fae9cba65..2446f0f68 100644 --- a/src/ImageSharp/Formats/Gif/GifEncoder.cs +++ b/src/ImageSharp/Formats/Gif/GifEncoder.cs @@ -32,10 +32,9 @@ namespace ImageSharp.Formats public IQuantizer Quantizer { get; set; } /// - public void Encode(Image image, Stream stream) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable - { + public void Encode(Image image, Stream stream) + where TColor : struct, IPackedPixel, IEquatable + { GifEncoderCore encoder = new GifEncoderCore { Quality = this.Quality, diff --git a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs index b968256b7..6b99423ae 100644 --- a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs @@ -45,22 +45,20 @@ namespace ImageSharp.Formats public IQuantizer Quantizer { get; set; } /// - /// Encodes the image to the specified stream from the . + /// Encodes the image to the specified stream from the . /// /// The pixel format. - /// The packed format. uint, long, float. - /// The to encode from. + /// The to encode from. /// The to encode the image data to. - public void Encode(Image image, Stream stream) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public void Encode(Image image, Stream stream) + where TColor : struct, IPackedPixel, IEquatable { Guard.NotNull(image, nameof(image)); Guard.NotNull(stream, nameof(stream)); if (this.Quantizer == null) { - this.Quantizer = new OctreeQuantizer(); + this.Quantizer = new OctreeQuantizer(); } // Do not use IDisposable pattern here as we want to preserve the stream. @@ -74,7 +72,7 @@ namespace ImageSharp.Formats this.bitDepth = ImageMaths.GetBitsNeededForColorDepth(this.Quality); // Quantize the image returning a palette. - QuantizedImage quantized = ((IQuantizer)this.Quantizer).Quantize(image, this.Quality); + QuantizedImage quantized = ((IQuantizer)this.Quantizer).Quantize(image, this.Quality); int index = this.GetTransparentIndex(quantized); @@ -98,8 +96,8 @@ namespace ImageSharp.Formats // ReSharper disable once ForCanBeConvertedToForeach for (int i = 0; i < image.Frames.Count; i++) { - ImageFrame frame = image.Frames[i]; - QuantizedImage quantizedFrame = ((IQuantizer)this.Quantizer).Quantize(frame, this.Quality); + ImageFrame frame = image.Frames[i]; + QuantizedImage quantizedFrame = ((IQuantizer)this.Quantizer).Quantize(frame, this.Quality); this.WriteGraphicalControlExtension(frame, writer, this.GetTransparentIndex(quantizedFrame)); this.WriteImageDescriptor(frame, writer); @@ -119,13 +117,11 @@ namespace ImageSharp.Formats /// The quantized. /// /// The pixel format. - /// The packed format. uint, long, float. /// /// The . /// - private int GetTransparentIndex(QuantizedImage quantized) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private int GetTransparentIndex(QuantizedImage quantized) + where TColor : struct, IPackedPixel, IEquatable { // Find the lowest alpha value and make it the transparent index. int index = 255; @@ -171,13 +167,11 @@ namespace ImageSharp.Formats /// Writes the logical screen descriptor to the stream. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image to encode. /// The writer to write to the stream with. /// The transparency index to set the default background index to. - private void WriteLogicalScreenDescriptor(Image image, EndianBinaryWriter writer, int tranparencyIndex) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private void WriteLogicalScreenDescriptor(Image image, EndianBinaryWriter writer, int tranparencyIndex) + where TColor : struct, IPackedPixel, IEquatable { GifLogicalScreenDescriptor descriptor = new GifLogicalScreenDescriptor { @@ -239,16 +233,11 @@ namespace ImageSharp.Formats /// Writes the graphics control extension to the stream. /// /// The pixel format. - /// The packed format. uint, long, float. - /// The to encode. + /// The to encode. /// The stream to write to. /// The index of the color in the color palette to make transparent. - private void WriteGraphicalControlExtension( - ImageBase image, - EndianBinaryWriter writer, - int transparencyIndex) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private void WriteGraphicalControlExtension(ImageBase image, EndianBinaryWriter writer, int transparencyIndex) + where TColor : struct, IPackedPixel, IEquatable { // TODO: Check transparency logic. bool hasTransparent = transparencyIndex < 255; @@ -287,12 +276,10 @@ namespace ImageSharp.Formats /// Writes the image descriptor to the stream. /// /// The pixel format. - /// The packed format. uint, long, float. - /// The to be encoded. + /// The to be encoded. /// The stream to write to. - private void WriteImageDescriptor(ImageBase image, EndianBinaryWriter writer) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private void WriteImageDescriptor(ImageBase image, EndianBinaryWriter writer) + where TColor : struct, IPackedPixel, IEquatable { writer.Write(GifConstants.ImageDescriptorLabel); // 2c // TODO: Can we capture this? @@ -314,12 +301,10 @@ namespace ImageSharp.Formats /// Writes the color table to the stream. /// /// The pixel format. - /// The packed format. uint, long, float. - /// The to encode. + /// The to encode. /// The writer to write to the stream with. - private void WriteColorTable(QuantizedImage image, EndianBinaryWriter writer) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private void WriteColorTable(QuantizedImage image, EndianBinaryWriter writer) + where TColor : struct, IPackedPixel, IEquatable { // Grab the palette and write it to the stream. int pixelCount = image.Palette.Length; @@ -351,12 +336,10 @@ namespace ImageSharp.Formats /// Writes the image pixel data to the stream. /// /// The pixel format. - /// The packed format. uint, long, float. - /// The containing indexed pixels. + /// The containing indexed pixels. /// The stream to write to. - private void WriteImageData(QuantizedImage image, EndianBinaryWriter writer) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private void WriteImageData(QuantizedImage image, EndianBinaryWriter writer) + where TColor : struct, IPackedPixel, IEquatable { using (LzwEncoder encoder = new LzwEncoder(image.Pixels, (byte)this.bitDepth)) { @@ -364,4 +347,4 @@ namespace ImageSharp.Formats } } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Formats/IImageDecoder.cs b/src/ImageSharp/Formats/IImageDecoder.cs index 1317ee4a5..d723b82f0 100644 --- a/src/ImageSharp/Formats/IImageDecoder.cs +++ b/src/ImageSharp/Formats/IImageDecoder.cs @@ -14,14 +14,12 @@ namespace ImageSharp.Formats public interface IImageDecoder { /// - /// Decodes the image from the specified stream to the . + /// Decodes the image from the specified stream to the . /// /// The pixel format. - /// The packed format. uint, long, float. - /// The to decode to. + /// The to decode to. /// The containing image data. - void Decode(Image image, Stream stream) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable; + void Decode(Image image, Stream stream) + where TColor : struct, IPackedPixel, IEquatable; } } diff --git a/src/ImageSharp/Formats/IImageEncoder.cs b/src/ImageSharp/Formats/IImageEncoder.cs index f3ead2a11..edde5347e 100644 --- a/src/ImageSharp/Formats/IImageEncoder.cs +++ b/src/ImageSharp/Formats/IImageEncoder.cs @@ -14,14 +14,12 @@ namespace ImageSharp.Formats public interface IImageEncoder { /// - /// Encodes the image to the specified stream from the . + /// Encodes the image to the specified stream from the . /// /// The pixel format. - /// The packed format. uint, long, float. - /// The to encode from. + /// The to encode from. /// The to encode the image data to. - void Encode(Image image, Stream stream) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable; + void Encode(Image image, Stream stream) + where TColor : struct, IPackedPixel, IEquatable; } } diff --git a/src/ImageSharp/Formats/Jpg/JpegDecoder.cs b/src/ImageSharp/Formats/Jpg/JpegDecoder.cs index b9e9aa1b2..9ee216b4d 100644 --- a/src/ImageSharp/Formats/Jpg/JpegDecoder.cs +++ b/src/ImageSharp/Formats/Jpg/JpegDecoder.cs @@ -14,10 +14,9 @@ namespace ImageSharp.Formats public class JpegDecoder : IImageDecoder { /// - public void Decode(Image image, Stream stream) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable - { + public void Decode(Image image, Stream stream) + where TColor : struct, IPackedPixel, IEquatable + { Guard.NotNull(image, "image"); Guard.NotNull(stream, "stream"); diff --git a/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs index 3991c4e0e..e302e064c 100644 --- a/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs @@ -267,13 +267,11 @@ namespace ImageSharp.Formats /// the data to image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image, where the data should be set to. /// The stream, where the image should be. /// Whether to decode metadata only. - public void Decode(Image image, Stream stream, bool configOnly) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public void Decode(Image image, Stream stream, bool configOnly) + where TColor : struct, IPackedPixel, IEquatable { this.inputStream = stream; @@ -511,15 +509,13 @@ namespace ImageSharp.Formats /// This is faster than implicit casting as it avoids double packing. /// /// The pixel format. - /// The packed format. uint, long, float. /// The packed pixel. /// The y luminance component. /// The cb chroma component. /// The cr chroma component. [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static void PackYcbCr(ref TColor packed, byte y, byte cb, byte cr) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private static void PackYcbCr(ref TColor packed, byte y, byte cb, byte cr) + where TColor : struct, IPackedPixel, IEquatable { int ccb = cb - 128; int ccr = cr - 128; @@ -1167,12 +1163,10 @@ namespace ImageSharp.Formats /// Processes the App1 marker retrieving any stored metadata /// /// The pixel format. - /// The packed format. uint, long, float. /// The remaining bytes in the segment block. /// The image. - private void ProcessApp1Marker(int remaining, Image image) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private void ProcessApp1Marker(int remaining, Image image) + where TColor : struct, IPackedPixel, IEquatable { if (remaining < 6) { @@ -1224,19 +1218,17 @@ namespace ImageSharp.Formats /// Converts the image from the original YCCK image pixels. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image width. /// The image height. /// The image. - private void ConvertFromYcck(int width, int height, Image image) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private void ConvertFromYcck(int width, int height, Image image) + where TColor : struct, IPackedPixel, IEquatable { int scale = this.componentArray[0].HorizontalFactor / this.componentArray[1].HorizontalFactor; image.InitPixels(width, height); - using (PixelAccessor pixels = image.Lock()) + using (PixelAccessor pixels = image.Lock()) { Parallel.For( 0, @@ -1253,7 +1245,7 @@ namespace ImageSharp.Formats byte cr = this.ycbcrImage.CrChannel[co + (x / scale)]; TColor packed = default(TColor); - this.PackYcck(ref packed, yy, cb, cr, x, y); + this.PackYcck(ref packed, yy, cb, cr, x, y); pixels[x, y] = packed; } }); @@ -1266,19 +1258,17 @@ namespace ImageSharp.Formats /// Converts the image from the original CMYK image pixels. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image width. /// The image height. /// The image. - private void ConvertFromCmyk(int width, int height, Image image) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private void ConvertFromCmyk(int width, int height, Image image) + where TColor : struct, IPackedPixel, IEquatable { int scale = this.componentArray[0].HorizontalFactor / this.componentArray[1].HorizontalFactor; image.InitPixels(width, height); - using (PixelAccessor pixels = image.Lock()) + using (PixelAccessor pixels = image.Lock()) { Parallel.For( 0, @@ -1295,7 +1285,7 @@ namespace ImageSharp.Formats byte yellow = this.ycbcrImage.CrChannel[co + (x / scale)]; TColor packed = default(TColor); - this.PackCmyk(ref packed, cyan, magenta, yellow, x, y); + this.PackCmyk(ref packed, cyan, magenta, yellow, x, y); pixels[x, y] = packed; } }); @@ -1308,17 +1298,15 @@ namespace ImageSharp.Formats /// Converts the image from the original grayscale image pixels. /// /// The pixel format. - /// The packed format. long, float. /// The image width. /// The image height. /// The image. - private void ConvertFromGrayScale(int width, int height, Image image) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private void ConvertFromGrayScale(int width, int height, Image image) + where TColor : struct, IPackedPixel, IEquatable { image.InitPixels(width, height); - using (PixelAccessor pixels = image.Lock()) + using (PixelAccessor pixels = image.Lock()) { Parallel.For( 0, @@ -1345,18 +1333,16 @@ namespace ImageSharp.Formats /// Converts the image from the original YCbCr image pixels. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image width. /// The image height. /// The image. - private void ConvertFromYCbCr(int width, int height, Image image) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private void ConvertFromYCbCr(int width, int height, Image image) + where TColor : struct, IPackedPixel, IEquatable { int scale = this.componentArray[0].HorizontalFactor / this.componentArray[1].HorizontalFactor; image.InitPixels(width, height); - using (PixelAccessor pixels = image.Lock()) + using (PixelAccessor pixels = image.Lock()) { Parallel.For( 0, @@ -1374,7 +1360,7 @@ namespace ImageSharp.Formats byte cr = this.ycbcrImage.CrChannel[co + (x / scale)]; TColor packed = default(TColor); - PackYcbCr(ref packed, yy, cb, cr); + PackYcbCr(ref packed, yy, cb, cr); pixels[x, y] = packed; } }); @@ -1387,18 +1373,16 @@ namespace ImageSharp.Formats /// Converts the image from the original RBG image pixels. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image width. /// The height. /// The image. - private void ConvertFromRGB(int width, int height, Image image) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private void ConvertFromRGB(int width, int height, Image image) + where TColor : struct, IPackedPixel, IEquatable { int scale = this.componentArray[0].HorizontalFactor / this.componentArray[1].HorizontalFactor; image.InitPixels(width, height); - using (PixelAccessor pixels = image.Lock()) + using (PixelAccessor pixels = image.Lock()) { Parallel.For( 0, @@ -1429,11 +1413,9 @@ namespace ImageSharp.Formats /// Assigns the horizontal and vertical resolution to the image if it has a JFIF header. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image to assign the resolution to. - private void AssignResolution(Image image) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private void AssignResolution(Image image) + where TColor : struct, IPackedPixel, IEquatable { if (this.isJfif && this.horizontalResolution > 0 && this.verticalResolution > 0) { @@ -2186,16 +2168,14 @@ namespace ImageSharp.Formats /// This is faster than implicit casting as it avoids double packing. /// /// The pixel format. - /// The packed format. uint, long, float. /// The packed pixel. /// The y luminance component. /// The cb chroma component. /// The cr chroma component. /// The x-position within the image. /// The y-position within the image. - private void PackYcck(ref TColor packed, byte y, byte cb, byte cr, int xx, int yy) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private void PackYcck(ref TColor packed, byte y, byte cb, byte cr, int xx, int yy) + where TColor : struct, IPackedPixel, IEquatable { // Convert the YCbCr part of the YCbCrK to RGB, invert the RGB to get // CMY, and patch in the original K. The RGB to CMY inversion cancels @@ -2226,16 +2206,14 @@ namespace ImageSharp.Formats /// This is faster than implicit casting as it avoids double packing. /// /// The pixel format. - /// The packed format. uint, long, float. /// The packed pixel. /// The cyan component. /// The magenta component. /// The yellow component. /// The x-position within the image. /// The y-position within the image. - private void PackCmyk(ref TColor packed, byte c, byte m, byte y, int xx, int yy) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private void PackCmyk(ref TColor packed, byte c, byte m, byte y, int xx, int yy) + where TColor : struct, IPackedPixel, IEquatable { // Get keyline float keyline = (255 - this.blackPixels[(yy * this.blackStride) + xx]) / 255F; diff --git a/src/ImageSharp/Formats/Jpg/JpegEncoder.cs b/src/ImageSharp/Formats/Jpg/JpegEncoder.cs index 623c518c4..18fd99008 100644 --- a/src/ImageSharp/Formats/Jpg/JpegEncoder.cs +++ b/src/ImageSharp/Formats/Jpg/JpegEncoder.cs @@ -61,10 +61,9 @@ namespace ImageSharp.Formats } /// - public void Encode(Image image, Stream stream) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable - { + public void Encode(Image image, Stream stream) + where TColor : struct, IPackedPixel, IEquatable + { JpegEncoderCore encode = new JpegEncoderCore(); if (this.subsampleSet) { diff --git a/src/ImageSharp/Formats/Jpg/JpegEncoderCore.cs b/src/ImageSharp/Formats/Jpg/JpegEncoderCore.cs index 55901033c..c1c4e9b57 100644 --- a/src/ImageSharp/Formats/Jpg/JpegEncoderCore.cs +++ b/src/ImageSharp/Formats/Jpg/JpegEncoderCore.cs @@ -287,14 +287,12 @@ namespace ImageSharp.Formats /// Encode writes the image to the jpeg baseline format with the given options. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image to write from. /// The stream to write to. /// The quality. /// The subsampling mode. - public void Encode(Image image, Stream stream, int quality, JpegSubsample sample) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public void Encode(Image image, Stream stream, int quality, JpegSubsample sample) + where TColor : struct, IPackedPixel, IEquatable { Guard.NotNull(image, nameof(image)); Guard.NotNull(stream, nameof(stream)); @@ -373,7 +371,7 @@ namespace ImageSharp.Formats this.WriteDefineHuffmanTables(componentCount); // Write the image data. - using (PixelAccessor pixels = image.Lock()) + using (PixelAccessor pixels = image.Lock()) { this.WriteStartOfScan(pixels); } @@ -539,16 +537,14 @@ namespace ImageSharp.Formats /// Converts the 8x8 region of the image whose top-left corner is x,y to its YCbCr values. /// /// The pixel format. - /// The packed format. uint, long, float. /// The pixel accessor. /// The x-position within the image. /// The y-position within the image. /// The luminance block. /// The red chroma block. /// The blue chroma block. - private void ToYCbCr(PixelAccessor pixels, int x, int y, ref Block yBlock, ref Block cbBlock, ref Block crBlock) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private void ToYCbCr(PixelAccessor pixels, int x, int y, ref Block yBlock, ref Block cbBlock, ref Block crBlock) + where TColor : struct, IPackedPixel, IEquatable { int xmax = pixels.Width - 1; int ymax = pixels.Height - 1; @@ -644,10 +640,8 @@ namespace ImageSharp.Formats /// /// The image. /// The pixel format. - /// The packed format. uint, long, float. - private void WriteProfiles(Image image) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private void WriteProfiles(Image image) + where TColor : struct, IPackedPixel, IEquatable { this.WriteProfile(image.ExifProfile); } @@ -817,13 +811,11 @@ namespace ImageSharp.Formats /// Writes the StartOfScan marker. /// /// The pixel format. - /// The packed format. uint, long, float. /// /// The pixel accessor providing access to the image pixels. /// - private void WriteStartOfScan(PixelAccessor pixels) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private void WriteStartOfScan(PixelAccessor pixels) + where TColor : struct, IPackedPixel, IEquatable { // TODO: We should allow grayscale writing. this.outputStream.Write(this.sosHeaderYCbCr, 0, this.sosHeaderYCbCr.Length); @@ -846,11 +838,9 @@ namespace ImageSharp.Formats /// Encodes the image with no subsampling. /// /// The pixel format. - /// The packed format. uint, long, float. /// The pixel accessor providing access to the image pixels. - private void Encode444(PixelAccessor pixels) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private void Encode444(PixelAccessor pixels) + where TColor : struct, IPackedPixel, IEquatable { Block b = Block.Create(); Block cb = Block.Create(); @@ -880,11 +870,9 @@ namespace ImageSharp.Formats /// at a factor of 2 both horizontally and vertically. /// /// The pixel format. - /// The packed format. uint, long, float. /// The pixel accessor providing access to the image pixels. - private void Encode420(PixelAccessor pixels) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private void Encode420(PixelAccessor pixels) + where TColor : struct, IPackedPixel, IEquatable { Block b = Block.Create(); Block[] cb = Block.CreateArray(4); diff --git a/src/ImageSharp/Formats/Png/PngDecoder.cs b/src/ImageSharp/Formats/Png/PngDecoder.cs index 8c4655b1d..845f0f222 100644 --- a/src/ImageSharp/Formats/Png/PngDecoder.cs +++ b/src/ImageSharp/Formats/Png/PngDecoder.cs @@ -31,15 +31,13 @@ namespace ImageSharp.Formats public class PngDecoder : IImageDecoder { /// - /// Decodes the image from the specified stream to the . + /// Decodes the image from the specified stream to the . /// /// The pixel format. - /// The packed format. uint, long, float. - /// The to decode to. + /// The to decode to. /// The containing image data. - public void Decode(Image image, Stream stream) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public void Decode(Image image, Stream stream) + where TColor : struct, IPackedPixel, IEquatable { new PngDecoderCore().Decode(image, stream); } diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index 0a6212a07..ed5862e07 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -129,8 +129,7 @@ namespace ImageSharp.Formats /// Decodes the stream to the image. /// /// The pixel format. - /// The packed format. uint, long, float. - /// The image to decode to. + /// The image to decode to. /// The stream containing image data. /// /// Thrown if the stream does not contain and end chunk. @@ -138,11 +137,10 @@ namespace ImageSharp.Formats /// /// Thrown if the image is larger than the maximum allowable size. /// - public void Decode(Image image, Stream stream) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable - { - Image currentImage = image; + public void Decode(Image image, Stream stream) + where TColor : struct, IPackedPixel, IEquatable + { + Image currentImage = image; this.currentStream = stream; this.currentStream.Skip(8); @@ -205,7 +203,7 @@ namespace ImageSharp.Formats image.InitPixels(this.header.Width, this.header.Height); - using (PixelAccessor pixels = image.Lock()) + using (PixelAccessor pixels = image.Lock()) { this.ReadScanlines(dataStream, pixels); } @@ -261,13 +259,11 @@ namespace ImageSharp.Formats /// Reads the data chunk containing physical dimension data. /// /// The pixel format. - /// The packed format. uint, long, float. - /// The image to read to. + /// The image to read to. /// The data containing physical data. - private void ReadPhysicalChunk(Image image, byte[] data) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable - { + private void ReadPhysicalChunk(Image image, byte[] data) + where TColor : struct, IPackedPixel, IEquatable + { data.ReverseBytes(0, 4); data.ReverseBytes(4, 4); @@ -326,13 +322,11 @@ namespace ImageSharp.Formats /// Reads the scanlines within the image. /// /// The pixel format. - /// The packed format. uint, long, float. - /// The containing data. + /// The containing data. /// The pixel data. - private void ReadScanlines(MemoryStream dataStream, PixelAccessor pixels) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable - { + private void ReadScanlines(MemoryStream dataStream, PixelAccessor pixels) + where TColor : struct, IPackedPixel, IEquatable + { this.bytesPerPixel = this.CalculateBytesPerPixel(); this.bytesPerScanline = this.CalculateScanlineLength(this.header.Width) + 1; this.bytesPerSample = 1; @@ -359,13 +353,11 @@ namespace ImageSharp.Formats /// Decodes the raw pixel data row by row /// /// The pixel format. - /// The packed format. uint, long, float. - /// The compressed pixel data stream. + /// The compressed pixel data stream. /// The image pixel accessor. - private void DecodePixelData(Stream compressedStream, PixelAccessor pixels) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable - { + private void DecodePixelData(Stream compressedStream, PixelAccessor pixels) + where TColor : struct, IPackedPixel, IEquatable + { byte[] previousScanline = ArrayPool.Shared.Rent(this.bytesPerScanline); byte[] scanline = ArrayPool.Shared.Rent(this.bytesPerScanline); @@ -433,13 +425,11 @@ namespace ImageSharp.Formats /// /// /// The pixel format. - /// The packed format. uint, long, float. - /// The compressed pixel data stream. + /// The compressed pixel data stream. /// The image pixel accessor. - private void DecodeInterlacedPixelData(Stream compressedStream, PixelAccessor pixels) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable - { + private void DecodeInterlacedPixelData(Stream compressedStream, PixelAccessor pixels) + where TColor : struct, IPackedPixel, IEquatable + { byte[] previousScanline = ArrayPool.Shared.Rent(this.bytesPerScanline); byte[] scanline = ArrayPool.Shared.Rent(this.bytesPerScanline); @@ -522,14 +512,12 @@ namespace ImageSharp.Formats /// Processes the de-filtered scanline filling the image pixel data /// /// The pixel format. - /// The packed format. uint, long, float. - /// The de-filtered scanline + /// The de-filtered scanline /// The current image row. /// The image pixels - private void ProcessDefilteredScanline(byte[] defilteredScanline, int row, PixelAccessor pixels) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable - { + private void ProcessDefilteredScanline(byte[] defilteredScanline, int row, PixelAccessor pixels) + where TColor : struct, IPackedPixel, IEquatable + { TColor color = default(TColor); switch (this.PngColorType) { @@ -647,16 +635,14 @@ namespace ImageSharp.Formats /// Processes the interlaced de-filtered scanline filling the image pixel data /// /// The pixel format. - /// The packed format. uint, long, float. - /// The de-filtered scanline + /// The de-filtered scanline /// The current image row. /// The image pixels /// The column start index. Always 0 for none interlaced images. /// The column increment. Always 1 for none interlaced images. - private void ProcessInterlacedDefilteredScanline(byte[] defilteredScanline, int row, PixelAccessor pixels, int pixelOffset = 0, int increment = 1) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable - { + private void ProcessInterlacedDefilteredScanline(byte[] defilteredScanline, int row, PixelAccessor pixels, int pixelOffset = 0, int increment = 1) + where TColor : struct, IPackedPixel, IEquatable + { TColor color = default(TColor); switch (this.PngColorType) @@ -769,14 +755,12 @@ namespace ImageSharp.Formats /// Reads a text chunk containing image properties from the data. /// /// The pixel format. - /// The packed format. uint, long, float. - /// The image to decode to. + /// The image to decode to. /// The containing data. /// The maximum length to read. - private void ReadTextChunk(Image image, byte[] data, int length) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable - { + private void ReadTextChunk(Image image, byte[] data, int length) + where TColor : struct, IPackedPixel, IEquatable + { int zeroIndex = 0; for (int i = 0; i < length; i++) diff --git a/src/ImageSharp/Formats/Png/PngEncoder.cs b/src/ImageSharp/Formats/Png/PngEncoder.cs index b5096f441..13125e30e 100644 --- a/src/ImageSharp/Formats/Png/PngEncoder.cs +++ b/src/ImageSharp/Formats/Png/PngEncoder.cs @@ -56,10 +56,9 @@ namespace ImageSharp.Formats public bool WriteGamma { get; set; } /// - public void Encode(Image image, Stream stream) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable - { + public void Encode(Image image, Stream stream) + where TColor : struct, IPackedPixel, IEquatable + { PngEncoderCore encoder = new PngEncoderCore { CompressionLevel = this.CompressionLevel, diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index abc6b2da7..7d3d23265 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -126,15 +126,13 @@ namespace ImageSharp.Formats public byte Threshold { get; set; } /// - /// Encodes the image to the specified stream from the . + /// Encodes the image to the specified stream from the . /// /// The pixel format. - /// The packed format. uint, long, float. - /// The to encode from. + /// The to encode from. /// The to encode the image data to. - public void Encode(ImageBase image, Stream stream) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public void Encode(ImageBase image, Stream stream) + where TColor : struct, IPackedPixel, IEquatable { Guard.NotNull(image, nameof(image)); Guard.NotNull(stream, nameof(stream)); @@ -207,7 +205,7 @@ namespace ImageSharp.Formats this.WritePhysicalChunk(stream, image); this.WriteGammaChunk(stream); - using (PixelAccessor pixels = image.Lock()) + using (PixelAccessor pixels = image.Lock()) { this.WriteDataChunks(pixels, stream); } @@ -260,16 +258,14 @@ namespace ImageSharp.Formats /// Collects the indexed pixel data. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image to encode. /// The containing image data. /// The . - private void CollectIndexedBytes(ImageBase image, Stream stream, PngHeader header) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private void CollectIndexedBytes(ImageBase image, Stream stream, PngHeader header) + where TColor : struct, IPackedPixel, IEquatable { // Quantize the image and get the pixels. - QuantizedImage quantized = this.WritePaletteChunk(stream, header, image); + QuantizedImage quantized = this.WritePaletteChunk(stream, header, image); this.palettePixelData = quantized.Pixels; } @@ -277,13 +273,11 @@ namespace ImageSharp.Formats /// Collects a row of grayscale pixels. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image pixels accessor. /// The row index. /// The raw scanline. - private void CollectGrayscaleBytes(PixelAccessor pixels, int row, byte[] rawScanline) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private void CollectGrayscaleBytes(PixelAccessor pixels, int row, byte[] rawScanline) + where TColor : struct, IPackedPixel, IEquatable { // Copy the pixels across from the image. // Reuse the chunk type buffer. @@ -313,16 +307,14 @@ namespace ImageSharp.Formats /// Collects a row of true color pixel data. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image pixel accessor. /// The row index. /// The raw scanline. - private void CollectColorBytes(PixelAccessor pixels, int row, byte[] rawScanline) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private void CollectColorBytes(PixelAccessor pixels, int row, byte[] rawScanline) + where TColor : struct, IPackedPixel, IEquatable { // We can use the optimized PixelAccessor here and copy the bytes in unmanaged memory. - using (PixelArea pixelRow = new PixelArea(this.width, rawScanline, this.bytesPerPixel == 4 ? ComponentOrder.XYZW : ComponentOrder.XYZ)) + using (PixelArea pixelRow = new PixelArea(this.width, rawScanline, this.bytesPerPixel == 4 ? ComponentOrder.XYZW : ComponentOrder.XYZ)) { pixels.CopyTo(pixelRow, row); } @@ -333,16 +325,14 @@ namespace ImageSharp.Formats /// Each scanline is encoded in the most optimal manner to improve compression. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image pixel accessor. /// The row. /// The previous scanline. /// The raw scanline. /// The filtered scanline result. /// The - private byte[] EncodePixelRow(PixelAccessor pixels, int row, byte[] previousScanline, byte[] rawScanline, byte[] result) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private byte[] EncodePixelRow(PixelAccessor pixels, int row, byte[] previousScanline, byte[] rawScanline, byte[] result) + where TColor : struct, IPackedPixel, IEquatable { switch (this.PngColorType) { @@ -482,14 +472,12 @@ namespace ImageSharp.Formats /// Writes the palette chunk to the stream. /// /// The pixel format. - /// The packed format. uint, long, float. /// The containing image data. /// The . /// The image to encode. - /// The - private QuantizedImage WritePaletteChunk(Stream stream, PngHeader header, ImageBase image) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The + private QuantizedImage WritePaletteChunk(Stream stream, PngHeader header, ImageBase image) + where TColor : struct, IPackedPixel, IEquatable { if (this.Quality > 256) { @@ -498,11 +486,11 @@ namespace ImageSharp.Formats if (this.Quantizer == null) { - this.Quantizer = new WuQuantizer(); + this.Quantizer = new WuQuantizer(); } // Quantize the image returning a palette. This boxing is icky. - QuantizedImage quantized = ((IQuantizer)this.Quantizer).Quantize(image, this.Quality); + QuantizedImage quantized = ((IQuantizer)this.Quantizer).Quantize(image, this.Quality); // Grab the palette and write it to the stream. TColor[] palette = quantized.Palette; @@ -554,14 +542,12 @@ namespace ImageSharp.Formats /// Writes the physical dimension information to the stream. /// /// The pixel format. - /// The packed format. uint, long, float. /// The containing image data. /// The image base. - private void WritePhysicalChunk(Stream stream, ImageBase imageBase) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private void WritePhysicalChunk(Stream stream, ImageBase imageBase) + where TColor : struct, IPackedPixel, IEquatable { - Image image = imageBase as Image; + Image image = imageBase as Image; if (image != null && image.HorizontalResolution > 0 && image.VerticalResolution > 0) { // 39.3700787 = inches in a meter. @@ -602,12 +588,10 @@ namespace ImageSharp.Formats /// Writes the pixel information to the stream. /// /// The pixel format. - /// The packed format. uint, long, float. /// The pixel accessor. /// The stream. - private void WriteDataChunks(PixelAccessor pixels, Stream stream) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private void WriteDataChunks(PixelAccessor pixels, Stream stream) + where TColor : struct, IPackedPixel, IEquatable { int bytesPerScanline = this.width * this.bytesPerPixel; byte[] previousScanline = new byte[bytesPerScanline]; diff --git a/src/ImageSharp/Image.cs b/src/ImageSharp/Image.cs index 8c03d64e9..22975a3c4 100644 --- a/src/ImageSharp/Image.cs +++ b/src/ImageSharp/Image.cs @@ -13,7 +13,7 @@ namespace ImageSharp /// packed into a single unsigned integer value. /// [DebuggerDisplay("Image: {Width}x{Height}")] - public class Image : Image + public class Image : Image { /// /// Initializes a new instance of the class. @@ -69,13 +69,13 @@ namespace ImageSharp } /// - public override PixelAccessor Lock() + public override PixelAccessor Lock() { return new PixelAccessor(this); } /// - internal override ImageFrame ToFrame() + internal override ImageFrame ToFrame() { return new ImageFrame(this); } diff --git a/src/ImageSharp/Image/IImageBase.cs b/src/ImageSharp/Image/IImageBase{TColor}.cs similarity index 90% rename from src/ImageSharp/Image/IImageBase.cs rename to src/ImageSharp/Image/IImageBase{TColor}.cs index 59c9baf70..bd5b31712 100644 --- a/src/ImageSharp/Image/IImageBase.cs +++ b/src/ImageSharp/Image/IImageBase{TColor}.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -11,10 +11,8 @@ namespace ImageSharp /// Encapsulates the basic properties and methods required to manipulate images in varying formats. /// /// The pixel format. - /// The packed format. uint, long, float. - public interface IImageBase : IImageBase - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public interface IImageBase : IImageBase + where TColor : struct, IPackedPixel, IEquatable { /// /// Gets the pixels as an array of the given packed pixel format. @@ -66,8 +64,8 @@ namespace ImageSharp /// It is imperative that the accessor is correctly disposed off after use. /// /// - /// The - PixelAccessor Lock(); + /// The + PixelAccessor Lock(); } /// diff --git a/src/ImageSharp/Image/IImageFrame.cs b/src/ImageSharp/Image/IImageFrame.cs deleted file mode 100644 index b7f7049c2..000000000 --- a/src/ImageSharp/Image/IImageFrame.cs +++ /dev/null @@ -1,20 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp -{ - using System; - - /// - /// Represents a single frame in a animation. - /// - /// The pixel format. - /// The packed format. uint, long, float. - public interface IImageFrame : IImageBase - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable - { - } -} diff --git a/src/ImageSharp/Image/IImageFrame{TColor}.cs b/src/ImageSharp/Image/IImageFrame{TColor}.cs new file mode 100644 index 000000000..6ebda36c8 --- /dev/null +++ b/src/ImageSharp/Image/IImageFrame{TColor}.cs @@ -0,0 +1,18 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp +{ + using System; + + /// + /// Represents a single frame in a animation. + /// + /// The pixel format. + public interface IImageFrame : IImageBase + where TColor : struct, IPackedPixel, IEquatable + { + } +} diff --git a/src/ImageSharp/Image/ImageBase.cs b/src/ImageSharp/Image/ImageBase{TColor}.cs similarity index 80% rename from src/ImageSharp/Image/ImageBase.cs rename to src/ImageSharp/Image/ImageBase{TColor}.cs index 1cb4b2fb3..164b28160 100644 --- a/src/ImageSharp/Image/ImageBase.cs +++ b/src/ImageSharp/Image/ImageBase{TColor}.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -13,11 +13,9 @@ namespace ImageSharp /// images in different pixel formats. /// /// The pixel format. - /// The packed format. uint, long, float. [DebuggerDisplay("Image: {Width}x{Height}")] - public abstract class ImageBase : IImageBase - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public abstract class ImageBase : IImageBase + where TColor : struct, IPackedPixel, IEquatable { /// /// The image pixels @@ -25,14 +23,14 @@ namespace ImageSharp private TColor[] pixelBuffer; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// protected ImageBase() { } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The width of the image in pixels. /// The height of the image in pixels. @@ -45,15 +43,15 @@ namespace ImageSharp } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// - /// The other to create this instance from. + /// The other to create this instance from. /// /// - /// Thrown if the given is null. + /// Thrown if the given is null. /// - protected ImageBase(ImageBase other) + protected ImageBase(ImageBase other) { Guard.NotNull(other, nameof(other), "Other image cannot be null."); @@ -63,8 +61,8 @@ namespace ImageSharp // Copy the pixels. Unsafe.CopyBlock gives us a nice speed boost here. this.pixelBuffer = new TColor[this.Width * this.Height]; - using (PixelAccessor sourcePixels = other.Lock()) - using (PixelAccessor target = this.Lock()) + using (PixelAccessor sourcePixels = other.Lock()) + using (PixelAccessor target = this.Lock()) { sourcePixels.CopyImage(target); } @@ -146,18 +144,18 @@ namespace ImageSharp } /// - public virtual PixelAccessor Lock() + public virtual PixelAccessor Lock() { - return new PixelAccessor(this); + return new PixelAccessor(this); } /// - /// Copies the properties from the other . + /// Copies the properties from the other . /// /// - /// The other to copy the properties from. + /// The other to copy the properties from. /// - protected void CopyProperties(ImageBase other) + protected void CopyProperties(ImageBase other) { this.Quality = other.Quality; this.FrameDelay = other.FrameDelay; diff --git a/src/ImageSharp/Image/ImageFrame.cs b/src/ImageSharp/Image/ImageFrame{TColor}.cs similarity index 63% rename from src/ImageSharp/Image/ImageFrame.cs rename to src/ImageSharp/Image/ImageFrame{TColor}.cs index dff5d1746..4c67bd968 100644 --- a/src/ImageSharp/Image/ImageFrame.cs +++ b/src/ImageSharp/Image/ImageFrame{TColor}.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -13,23 +13,21 @@ namespace ImageSharp /// Represents a single frame in a animation. /// /// The pixel format. - /// The packed format. uint, long, float. - public class ImageFrame : ImageBase - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class ImageFrame : ImageBase + where TColor : struct, IPackedPixel, IEquatable { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// public ImageFrame() { } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The image to create the frame from. - public ImageFrame(ImageBase image) + public ImageFrame(ImageBase image) : base(image) { } @@ -45,15 +43,13 @@ namespace ImageSharp /// /// A function that allows for the correction of vector scaling between unknown color formats. /// The pixel format. - /// The packed format. uint, long, float. - /// The - public ImageFrame To(Func scaleFunc = null) - where TColor2 : struct, IPackedPixel - where TPacked2 : struct, IEquatable + /// The + public ImageFrame To(Func scaleFunc = null) + where TColor2 : struct, IPackedPixel, IEquatable { scaleFunc = PackedPixelConverterHelper.ComputeScaleFunction(scaleFunc); - ImageFrame target = new ImageFrame + ImageFrame target = new ImageFrame { Quality = this.Quality, FrameDelay = this.FrameDelay @@ -61,8 +57,8 @@ namespace ImageSharp target.InitPixels(this.Width, this.Height); - using (PixelAccessor pixels = this.Lock()) - using (PixelAccessor targetPixels = target.Lock()) + using (PixelAccessor pixels = this.Lock()) + using (PixelAccessor targetPixels = target.Lock()) { Parallel.For( 0, @@ -85,10 +81,10 @@ namespace ImageSharp /// /// Clones the current instance. /// - /// The - internal virtual ImageFrame Clone() + /// The + internal virtual ImageFrame Clone() { - return new ImageFrame(this); + return new ImageFrame(this); } } } \ No newline at end of file diff --git a/src/ImageSharp/Image/ImageIOExtensions.cs b/src/ImageSharp/Image/ImageIOExtensions.cs index 959577bb8..fd76e9137 100644 --- a/src/ImageSharp/Image/ImageIOExtensions.cs +++ b/src/ImageSharp/Image/ImageIOExtensions.cs @@ -11,7 +11,7 @@ namespace ImageSharp using Formats; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -19,23 +19,20 @@ namespace ImageSharp /// Saves the image to the given stream with the bmp format. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The stream to save the image to. /// Thrown if the stream is null. /// - /// The . + /// The . /// - public static Image SaveAsBmp(this Image source, Stream stream) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable - => source.Save(stream, new BmpEncoder()); + public static Image SaveAsBmp(this Image source, Stream stream) + where TColor : struct, IPackedPixel, IEquatable + => source.Save(stream, new BmpEncoder()); /// /// Saves the image to the given stream with the png format. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The stream to save the image to. /// The quality to save the image to representing the number of colors. @@ -43,45 +40,40 @@ namespace ImageSharp /// /// Thrown if the stream is null. /// - /// The . + /// The . /// - public static Image SaveAsPng(this Image source, Stream stream, int quality = int.MaxValue) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable - => source.Save(stream, new PngEncoder { Quality = quality }); + public static Image SaveAsPng(this Image source, Stream stream, int quality = int.MaxValue) + where TColor : struct, IPackedPixel, IEquatable + => source.Save(stream, new PngEncoder { Quality = quality }); /// /// Saves the image to the given stream with the jpeg format. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The stream to save the image to. /// The quality to save the image to. Between 1 and 100. /// Thrown if the stream is null. /// - /// The . + /// The . /// - public static Image SaveAsJpeg(this Image source, Stream stream, int quality = 75) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable - => source.Save(stream, new JpegEncoder { Quality = quality }); + public static Image SaveAsJpeg(this Image source, Stream stream, int quality = 75) + where TColor : struct, IPackedPixel, IEquatable + => source.Save(stream, new JpegEncoder { Quality = quality }); /// /// Saves the image to the given stream with the gif format. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The stream to save the image to. /// The quality to save the image to representing the number of colors. Between 1 and 256. /// Thrown if the stream is null. /// - /// The . + /// The . /// - public static Image SaveAsGif(this Image source, Stream stream, int quality = 256) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable - => source.Save(stream, new GifEncoder { Quality = quality }); + public static Image SaveAsGif(this Image source, Stream stream, int quality = 256) + where TColor : struct, IPackedPixel, IEquatable + => source.Save(stream, new GifEncoder { Quality = quality }); } } diff --git a/src/ImageSharp/Image/ImageProcessingExtensions.cs b/src/ImageSharp/Image/ImageProcessingExtensions.cs index 81acfe863..16ce455d2 100644 --- a/src/ImageSharp/Image/ImageProcessingExtensions.cs +++ b/src/ImageSharp/Image/ImageProcessingExtensions.cs @@ -9,7 +9,7 @@ namespace ImageSharp using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -18,13 +18,11 @@ namespace ImageSharp /// This method does not resize the target image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The processor to apply to the image. - /// The . - internal static Image Process(this Image source, IImageFilteringProcessor processor) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + internal static Image Process(this Image source, IImageFilteringProcessor processor) + where TColor : struct, IPackedPixel, IEquatable { return Process(source, source.Bounds, processor); } @@ -34,16 +32,14 @@ namespace ImageSharp /// This method does not resize the target image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// /// The structure that specifies the portion of the image object to draw. /// /// The processors to apply to the image. - /// The . - internal static Image Process(this Image source, Rectangle sourceRectangle, IImageFilteringProcessor processor) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + internal static Image Process(this Image source, Rectangle sourceRectangle, IImageFilteringProcessor processor) + where TColor : struct, IPackedPixel, IEquatable { return PerformAction(source, (sourceImage) => processor.Apply(sourceImage, sourceRectangle)); } @@ -52,17 +48,15 @@ namespace ImageSharp /// Performs the given action on the source image. /// /// The pixel format. - /// The packed format. long, float. /// The image to perform the action against. /// The to perform against the image. - /// The . - private static Image PerformAction(Image source, Action> action) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + private static Image PerformAction(Image source, Action> action) + where TColor : struct, IPackedPixel, IEquatable { action(source); - foreach (ImageFrame sourceFrame in source.Frames) + foreach (ImageFrame sourceFrame in source.Frames) { action(sourceFrame); } diff --git a/src/ImageSharp/Image/Image.cs b/src/ImageSharp/Image/Image{TColor}.cs similarity index 85% rename from src/ImageSharp/Image/Image.cs rename to src/ImageSharp/Image/Image{TColor}.cs index 79e924b5d..198d46ea8 100644 --- a/src/ImageSharp/Image/Image.cs +++ b/src/ImageSharp/Image/Image{TColor}.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -21,11 +21,9 @@ namespace ImageSharp /// Encapsulates an image, which consists of the pixel data for a graphics image and its attributes. /// /// The pixel format. - /// The packed format. uint, long, float. [DebuggerDisplay("Image: {Width}x{Height}")] - public class Image : ImageBase - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class Image : ImageBase + where TColor : struct, IPackedPixel, IEquatable { /// /// The default horizontal resolution value (dots per inch) in x direction. @@ -40,7 +38,7 @@ namespace ImageSharp public const double DefaultVerticalResolution = 96; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// public Image() { @@ -48,7 +46,7 @@ namespace ImageSharp } /// - /// Initializes a new instance of the class + /// Initializes a new instance of the class /// with the height and the width of the image. /// /// The width of the image in pixels. @@ -60,7 +58,7 @@ namespace ImageSharp } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// The stream containing image information. @@ -73,7 +71,7 @@ namespace ImageSharp } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// The byte array containing image information. @@ -90,19 +88,19 @@ namespace ImageSharp } /// - /// Initializes a new instance of the class + /// Initializes a new instance of the class /// by making a copy from another image. /// /// The other image, where the clone should be made from. /// is null. - public Image(Image other) + public Image(Image other) : base(other) { - foreach (ImageFrame frame in other.Frames) + foreach (ImageFrame frame in other.Frames) { if (frame != null) { - this.Frames.Add(new ImageFrame(frame)); + this.Frames.Add(new ImageFrame(frame)); } } @@ -183,7 +181,7 @@ namespace ImageSharp /// Gets the other frames for the animation. /// /// The list of frame images. - public IList> Frames { get; } = new List>(); + public IList> Frames { get; } = new List>(); /// /// Gets the list of properties for storing meta information about this image. @@ -206,8 +204,8 @@ namespace ImageSharp /// /// The stream to save the image to. /// Thrown if the stream is null. - /// The - public Image Save(Stream stream) + /// The + public Image Save(Stream stream) { Guard.NotNull(stream, nameof(stream)); this.CurrentImageFormat.Encoder.Encode(this, stream); @@ -220,8 +218,8 @@ namespace ImageSharp /// The stream to save the image to. /// The format to save the image as. /// Thrown if the stream is null. - /// The - public Image Save(Stream stream, IImageFormat format) + /// The + public Image Save(Stream stream, IImageFormat format) { Guard.NotNull(stream, nameof(stream)); format.Encoder.Encode(this, stream); @@ -235,9 +233,9 @@ namespace ImageSharp /// The encoder to save the image with. /// Thrown if the stream is null. /// - /// The . + /// The . /// - public Image Save(Stream stream, IImageEncoder encoder) + public Image Save(Stream stream, IImageEncoder encoder) { Guard.NotNull(stream, nameof(stream)); encoder.Encode(this, stream); @@ -277,15 +275,13 @@ namespace ImageSharp /// /// A function that allows for the correction of vector scaling between unknown color formats. /// The pixel format. - /// The packed format. uint, long, float. - /// The - public Image To(Func scaleFunc = null) - where TColor2 : struct, IPackedPixel - where TPacked2 : struct, IEquatable + /// The + public Image To(Func scaleFunc = null) + where TColor2 : struct, IPackedPixel, IEquatable { scaleFunc = PackedPixelConverterHelper.ComputeScaleFunction(scaleFunc); - Image target = new Image(this.Width, this.Height) + Image target = new Image(this.Width, this.Height) { Quality = this.Quality, FrameDelay = this.FrameDelay, @@ -295,8 +291,8 @@ namespace ImageSharp RepeatCount = this.RepeatCount }; - using (PixelAccessor pixels = this.Lock()) - using (PixelAccessor targetPixels = target.Lock()) + using (PixelAccessor pixels = this.Lock()) + using (PixelAccessor targetPixels = target.Lock()) { Parallel.For( 0, @@ -318,21 +314,21 @@ namespace ImageSharp target.ExifProfile = new ExifProfile(this.ExifProfile); } - foreach (ImageFrame frame in this.Frames) + foreach (ImageFrame frame in this.Frames) { - target.Frames.Add(frame.To()); + target.Frames.Add(frame.To()); } return target; } /// - /// Copies the properties from the other . + /// Copies the properties from the other . /// /// - /// The other to copy the properties from. + /// The other to copy the properties from. /// - internal void CopyProperties(Image other) + internal void CopyProperties(Image other) { base.CopyProperties(other); @@ -348,12 +344,12 @@ namespace ImageSharp } /// - /// Creates a new from this instance + /// Creates a new from this instance /// - /// The - internal virtual ImageFrame ToFrame() + /// The + internal virtual ImageFrame ToFrame() { - return new ImageFrame(this); + return new ImageFrame(this); } /// @@ -429,7 +425,7 @@ namespace ImageSharp { long startPosition = stream.Position; stream.Read(header, 0, maxHeaderSize); - stream.Position = 0; + stream.Position = startPosition; format = Bootstrapper.ImageFormats.FirstOrDefault(x => x.IsSupportedFileFormat(header)); } finally diff --git a/src/ImageSharp/Image/PixelAccessor.cs b/src/ImageSharp/Image/PixelAccessor{TColor}.cs similarity index 90% rename from src/ImageSharp/Image/PixelAccessor.cs rename to src/ImageSharp/Image/PixelAccessor{TColor}.cs index 3baf9aeb1..3642d3942 100644 --- a/src/ImageSharp/Image/PixelAccessor.cs +++ b/src/ImageSharp/Image/PixelAccessor{TColor}.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -11,13 +11,11 @@ namespace ImageSharp using System.Runtime.InteropServices; /// - /// Provides per-pixel access to generic pixels. + /// Provides per-pixel access to generic pixels. /// /// The pixel format. - /// The packed format. uint, long, float. - public unsafe class PixelAccessor : IDisposable - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public unsafe class PixelAccessor : IDisposable + where TColor : struct, IPackedPixel, IEquatable { /// /// The pointer to the pixel buffer. @@ -46,10 +44,10 @@ namespace ImageSharp private bool isDisposed; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The image to provide pixel access for. - public PixelAccessor(ImageBase image) + public PixelAccessor(ImageBase image) { Guard.NotNull(image, nameof(image)); Guard.MustBeGreaterThan(image.Width, 0, "image width"); @@ -60,12 +58,12 @@ namespace ImageSharp this.pixelsHandle = GCHandle.Alloc(image.Pixels, GCHandleType.Pinned); this.dataPointer = this.pixelsHandle.AddrOfPinnedObject(); this.pixelsBase = (byte*)this.dataPointer.ToPointer(); - this.PixelSize = Unsafe.SizeOf(); + this.PixelSize = Unsafe.SizeOf(); this.RowStride = this.Width * this.PixelSize; } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// Gets the width of the image represented by the pixel buffer. /// The height of the image represented by the pixel buffer. @@ -86,12 +84,12 @@ namespace ImageSharp this.pixelsHandle = GCHandle.Alloc(pixels, GCHandleType.Pinned); this.dataPointer = this.pixelsHandle.AddrOfPinnedObject(); this.pixelsBase = (byte*)this.dataPointer.ToPointer(); - this.PixelSize = Unsafe.SizeOf(); + this.PixelSize = Unsafe.SizeOf(); this.RowStride = this.Width * this.PixelSize; } /// - /// Finalizes an instance of the class. + /// Finalizes an instance of the class. /// ~PixelAccessor() { @@ -155,7 +153,7 @@ namespace ImageSharp /// The x-coordinate of the target image. /// The y-coordinate of the target image. /// The number of pixels to copy - public void CopyBlock(int sourceX, int sourceY, PixelAccessor target, int targetX, int targetY, int pixelCount) + public void CopyBlock(int sourceX, int sourceY, PixelAccessor target, int targetX, int targetY, int pixelCount) { int size = Unsafe.SizeOf(); byte* sourcePtr = this.pixelsBase + (((sourceY * this.Width) + sourceX) * size); @@ -169,7 +167,7 @@ namespace ImageSharp /// Copies an entire image. /// /// The target pixel buffer accessor. - public void CopyImage(PixelAccessor target) + public void CopyImage(PixelAccessor target) { this.CopyBlock(0, 0, target, 0, 0, target.Width * target.Height); } @@ -183,7 +181,7 @@ namespace ImageSharp /// /// Thrown when an unsupported component order value is passed. /// - public void CopyFrom(PixelArea area, int targetY, int targetX = 0) + public void CopyFrom(PixelArea area, int targetY, int targetX = 0) { int width = Math.Min(area.Width, this.Width - targetX); int height = Math.Min(area.Height, this.Height - targetY); @@ -218,7 +216,7 @@ namespace ImageSharp /// /// Thrown when an unsupported component order value is passed. /// - public void CopyTo(PixelArea area, int sourceY, int sourceX = 0) + public void CopyTo(PixelArea area, int sourceY, int sourceX = 0) { int width = Math.Min(area.Width, this.Width - sourceX); int height = Math.Min(area.Height, this.Height - sourceY); @@ -289,7 +287,7 @@ namespace ImageSharp /// The target column index. /// The width. /// The height. - protected virtual void CopyFromZYX(PixelArea area, int targetY, int targetX, int width, int height) + protected virtual void CopyFromZYX(PixelArea area, int targetY, int targetX, int width, int height) { TColor packed = default(TColor); int size = Unsafe.SizeOf(); @@ -318,7 +316,7 @@ namespace ImageSharp /// The target column index. /// The width. /// The height. - protected virtual void CopyFromZYXW(PixelArea area, int targetY, int targetX, int width, int height) + protected virtual void CopyFromZYXW(PixelArea area, int targetY, int targetX, int width, int height) { TColor packed = default(TColor); int size = Unsafe.SizeOf(); @@ -347,7 +345,7 @@ namespace ImageSharp /// The target column index. /// The width. /// The height. - protected virtual void CopyFromXYZ(PixelArea area, int targetY, int targetX, int width, int height) + protected virtual void CopyFromXYZ(PixelArea area, int targetY, int targetX, int width, int height) { TColor packed = default(TColor); int size = Unsafe.SizeOf(); @@ -376,7 +374,7 @@ namespace ImageSharp /// The target column index. /// The width. /// The height. - protected virtual void CopyFromXYZW(PixelArea area, int targetY, int targetX, int width, int height) + protected virtual void CopyFromXYZW(PixelArea area, int targetY, int targetX, int width, int height) { TColor packed = default(TColor); int size = Unsafe.SizeOf(); @@ -405,7 +403,7 @@ namespace ImageSharp /// The source column index. /// The width. /// The height. - protected virtual void CopyToZYX(PixelArea area, int sourceY, int sourceX, int width, int height) + protected virtual void CopyToZYX(PixelArea area, int sourceY, int sourceX, int width, int height) { for (int y = 0; y < height; y++) { @@ -426,7 +424,7 @@ namespace ImageSharp /// The source column index. /// The width. /// The height. - protected virtual void CopyToZYXW(PixelArea area, int sourceY, int sourceX, int width, int height) + protected virtual void CopyToZYXW(PixelArea area, int sourceY, int sourceX, int width, int height) { for (int y = 0; y < height; y++) { @@ -447,7 +445,7 @@ namespace ImageSharp /// The source column index. /// The width. /// The height. - protected virtual void CopyToXYZ(PixelArea area, int sourceY, int sourceX, int width, int height) + protected virtual void CopyToXYZ(PixelArea area, int sourceY, int sourceX, int width, int height) { for (int y = 0; y < height; y++) { @@ -468,7 +466,7 @@ namespace ImageSharp /// The source column index. /// The width. /// The height. - protected virtual void CopyToXYZW(PixelArea area, int sourceY, int sourceX, int width, int height) + protected virtual void CopyToXYZW(PixelArea area, int sourceY, int sourceX, int width, int height) { for (int y = 0; y < height; y++) { @@ -494,6 +492,14 @@ namespace ImageSharp return this.pixelsBase + (((y * this.Width) + x) * Unsafe.SizeOf()); } + /// + /// Checks that the given dimensions are within the bounds of the image. + /// + /// The width. + /// The height. + /// + /// Thrown if the dimensions are not within the bounds of the image. + /// [Conditional("DEBUG")] private void CheckDimensions(int width, int height) { diff --git a/src/ImageSharp/Image/PixelArea.cs b/src/ImageSharp/Image/PixelArea{TColor}.cs similarity index 93% rename from src/ImageSharp/Image/PixelArea.cs rename to src/ImageSharp/Image/PixelArea{TColor}.cs index 9d063b753..2f631f66e 100644 --- a/src/ImageSharp/Image/PixelArea.cs +++ b/src/ImageSharp/Image/PixelArea{TColor}.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -12,13 +12,11 @@ namespace ImageSharp using System.Runtime.InteropServices; /// - /// Represents an area of generic pixels. + /// Represents an area of generic pixels. /// /// The pixel format. - /// The packed format. uint, long, float. - public sealed unsafe class PixelArea : IDisposable - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public sealed unsafe class PixelArea : IDisposable + where TColor : struct, IPackedPixel, IEquatable { /// /// Provides a way to access the pixels from unmanaged memory. @@ -42,7 +40,7 @@ namespace ImageSharp private bool isDisposed; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The width. /// The bytes. @@ -56,7 +54,7 @@ namespace ImageSharp } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The width. /// The height. @@ -82,7 +80,7 @@ namespace ImageSharp } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The width. /// The component order. @@ -92,7 +90,7 @@ namespace ImageSharp } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The width. /// The component order. @@ -103,7 +101,7 @@ namespace ImageSharp } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The width. /// The height. @@ -124,7 +122,7 @@ namespace ImageSharp } /// - /// Finalizes an instance of the class. + /// Finalizes an instance of the class. /// ~PixelArea() { diff --git a/src/ImageSharp/ImageFrame.cs b/src/ImageSharp/ImageFrame.cs index 0e4741f11..3ce264f38 100644 --- a/src/ImageSharp/ImageFrame.cs +++ b/src/ImageSharp/ImageFrame.cs @@ -11,7 +11,7 @@ namespace ImageSharp /// An optimized frame for the class. /// [DebuggerDisplay("ImageFrame: {Width}x{Height}")] - public class ImageFrame : ImageFrame + public class ImageFrame : ImageFrame { /// /// Initializes a new instance of the class. @@ -26,19 +26,19 @@ namespace ImageSharp /// /// The image to create the frame from. /// - public ImageFrame(ImageBase image) + public ImageFrame(ImageBase image) : base(image) { } /// - public override PixelAccessor Lock() + public override PixelAccessor Lock() { return new PixelAccessor(this); } /// - internal override ImageFrame Clone() + internal override ImageFrame Clone() { return new ImageFrame(this); } diff --git a/src/ImageSharp/ImageProcessor.cs b/src/ImageSharp/ImageProcessor.cs index 4b92eb5d1..46fcb574d 100644 --- a/src/ImageSharp/ImageProcessor.cs +++ b/src/ImageSharp/ImageProcessor.cs @@ -12,10 +12,8 @@ namespace ImageSharp.Processors /// Allows the application of processors to images. /// /// The pixel format. - /// The packed format. uint, long, float. - public abstract class ImageProcessor : IImageProcessor - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public abstract class ImageProcessor : IImageProcessor + where TColor : struct, IPackedPixel, IEquatable { /// public virtual ParallelOptions ParallelOptions { get; set; } = Bootstrapper.ParallelOptions; diff --git a/src/ImageSharp/PixelAccessor.cs b/src/ImageSharp/PixelAccessor.cs index 45fad4e6a..378ec55dc 100644 --- a/src/ImageSharp/PixelAccessor.cs +++ b/src/ImageSharp/PixelAccessor.cs @@ -10,19 +10,19 @@ namespace ImageSharp /// /// An optimized pixel accessor for the class. /// - public sealed unsafe class PixelAccessor : PixelAccessor + public sealed unsafe class PixelAccessor : PixelAccessor { /// /// Initializes a new instance of the class. /// /// The image to provide pixel access for. - public PixelAccessor(ImageBase image) + public PixelAccessor(ImageBase image) : base(image) { } /// - protected override void CopyFromXYZW(PixelArea area, int targetY, int targetX, int width, int height) + protected override void CopyFromXYZW(PixelArea area, int targetY, int targetX, int width, int height) { uint byteCount = (uint)width * 4; @@ -36,7 +36,7 @@ namespace ImageSharp } /// - protected override void CopyFromXYZ(PixelArea area, int targetY, int targetX, int width, int height) + protected override void CopyFromXYZ(PixelArea area, int targetY, int targetX, int width, int height) { for (int y = 0; y < height; y++) { @@ -54,7 +54,7 @@ namespace ImageSharp } /// - protected override void CopyFromZYX(PixelArea area, int targetY, int targetX, int width, int height) + protected override void CopyFromZYX(PixelArea area, int targetY, int targetX, int width, int height) { for (int y = 0; y < height; y++) { @@ -72,7 +72,7 @@ namespace ImageSharp } /// - protected override void CopyFromZYXW(PixelArea area, int targetY, int targetX, int width, int height) + protected override void CopyFromZYXW(PixelArea area, int targetY, int targetX, int width, int height) { for (int y = 0; y < height; y++) { @@ -90,7 +90,7 @@ namespace ImageSharp } /// - protected override void CopyToZYX(PixelArea area, int sourceY, int sourceX, int width, int height) + protected override void CopyToZYX(PixelArea area, int sourceY, int sourceX, int width, int height) { for (int y = 0; y < height; y++) { @@ -110,7 +110,7 @@ namespace ImageSharp } /// - protected override void CopyToZYXW(PixelArea area, int sourceY, int sourceX, int width, int height) + protected override void CopyToZYXW(PixelArea area, int sourceY, int sourceX, int width, int height) { for (int y = 0; y < height; y++) { diff --git a/src/ImageSharp/Profiles/Exif/ExifProfile.cs b/src/ImageSharp/Profiles/Exif/ExifProfile.cs index a03c404fa..507463985 100644 --- a/src/ImageSharp/Profiles/Exif/ExifProfile.cs +++ b/src/ImageSharp/Profiles/Exif/ExifProfile.cs @@ -117,13 +117,11 @@ namespace ImageSharp /// Returns the thumbnail in the EXIF profile when available. /// /// The pixel format. - /// The packed format. uint, long, float. /// - /// The . + /// The . /// - public Image CreateThumbnail() - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public Image CreateThumbnail() + where TColor : struct, IPackedPixel, IEquatable { this.InitializeValues(); @@ -139,7 +137,7 @@ namespace ImageSharp using (MemoryStream memStream = new MemoryStream(this.data, this.thumbnailOffset, this.thumbnailLength)) { - return new Image(memStream); + return new Image(memStream); } } diff --git a/src/ImageSharp/ProgressEventArgs.cs b/src/ImageSharp/ProgressEventArgs.cs deleted file mode 100644 index 585dd1b63..000000000 --- a/src/ImageSharp/ProgressEventArgs.cs +++ /dev/null @@ -1,23 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp -{ - /// - /// Contains event data related to the progress made processing an image. - /// - public class ProgressEventArgs : System.EventArgs - { - /// - /// Gets or sets the number of rows processed. - /// - public int RowsProcessed { get; set; } - - /// - /// Gets or sets the total number of rows. - /// - public int TotalRows { get; set; } - } -} \ No newline at end of file diff --git a/src/ImageSharp/Quantizers/IQuantizer.cs b/src/ImageSharp/Quantizers/IQuantizer.cs index 642c2817a..878e9775b 100644 --- a/src/ImageSharp/Quantizers/IQuantizer.cs +++ b/src/ImageSharp/Quantizers/IQuantizer.cs @@ -11,10 +11,8 @@ namespace ImageSharp.Quantizers /// Provides methods for allowing quantization of images pixels. /// /// The pixel format. - /// The packed format. uint, long, float. - public interface IQuantizer : IQuantizer - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public interface IQuantizer : IQuantizer + where TColor : struct, IPackedPixel, IEquatable { /// /// Quantize an image and return the resulting output pixels. @@ -24,7 +22,7 @@ namespace ImageSharp.Quantizers /// /// A representing a quantized version of the image pixels. /// - QuantizedImage Quantize(ImageBase image, int maxColors); + QuantizedImage Quantize(ImageBase image, int maxColors); } /// diff --git a/src/ImageSharp/Quantizers/Octree/OctreeQuantizer.cs b/src/ImageSharp/Quantizers/Octree/OctreeQuantizer.cs index 6bffeb5e1..2898a5b71 100644 --- a/src/ImageSharp/Quantizers/Octree/OctreeQuantizer.cs +++ b/src/ImageSharp/Quantizers/Octree/OctreeQuantizer.cs @@ -13,10 +13,8 @@ namespace ImageSharp.Quantizers /// /// /// The pixel format. - /// The packed format. uint, long, float. - public sealed class OctreeQuantizer : Quantizer - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public sealed class OctreeQuantizer : Quantizer + where TColor : struct, IPackedPixel, IEquatable { /// /// The pixel buffer, used to reduce allocations. @@ -34,7 +32,7 @@ namespace ImageSharp.Quantizers private int colors; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// The Octree quantizer is a two pass algorithm. The initial pass sets up the Octree, @@ -46,7 +44,7 @@ namespace ImageSharp.Quantizers } /// - public override QuantizedImage Quantize(ImageBase image, int maxColors) + public override QuantizedImage Quantize(ImageBase image, int maxColors) { this.colors = maxColors.Clamp(1, 255); @@ -144,7 +142,7 @@ namespace ImageSharp.Quantizers /// /// Cache the previous color quantized /// - private TPacked previousColor; + private TColor previousColor; /// /// Initializes a new instance of the class. @@ -158,7 +156,7 @@ namespace ImageSharp.Quantizers this.Leaves = 0; this.reducibleNodes = new OctreeNode[9]; this.root = new OctreeNode(0, this.maxColorBits, this); - this.previousColor = default(TPacked); + this.previousColor = default(TColor); this.previousNode = null; } @@ -179,16 +177,14 @@ namespace ImageSharp.Quantizers /// The buffer array. public void AddColor(TColor pixel, byte[] buffer) { - TPacked packed = pixel.PackedValue; - // Check if this request is for the same color as the last - if (this.previousColor.Equals(packed)) + if (this.previousColor.Equals(pixel)) { // If so, check if I have a previous node setup. This will only occur if the first color in the image // happens to be black, with an alpha component of zero. if (this.previousNode == null) { - this.previousColor = packed; + this.previousColor = pixel; this.root.AddColor(pixel, this.maxColorBits, 0, this, buffer); } else @@ -199,7 +195,7 @@ namespace ImageSharp.Quantizers } else { - this.previousColor = packed; + this.previousColor = pixel; this.root.AddColor(pixel, this.maxColorBits, 0, this, buffer); } } diff --git a/src/ImageSharp/Quantizers/Octree/Quantizer.cs b/src/ImageSharp/Quantizers/Octree/Quantizer.cs index c1301740a..74aa6aade 100644 --- a/src/ImageSharp/Quantizers/Octree/Quantizer.cs +++ b/src/ImageSharp/Quantizers/Octree/Quantizer.cs @@ -11,10 +11,8 @@ namespace ImageSharp.Quantizers /// Encapsulates methods to calculate the color palette of an image. /// /// The pixel format. - /// The packed format. uint, long, float. - public abstract class Quantizer : IQuantizer - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public abstract class Quantizer : IQuantizer + where TColor : struct, IPackedPixel, IEquatable { /// /// Flag used to indicate whether a single pass or two passes are needed for quantization. @@ -22,7 +20,7 @@ namespace ImageSharp.Quantizers private readonly bool singlePass; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// If true, the quantization only needs to loop through the source pixels once @@ -38,7 +36,7 @@ namespace ImageSharp.Quantizers } /// - public virtual QuantizedImage Quantize(ImageBase image, int maxColors) + public virtual QuantizedImage Quantize(ImageBase image, int maxColors) { Guard.NotNull(image, nameof(image)); @@ -48,7 +46,7 @@ namespace ImageSharp.Quantizers byte[] quantizedPixels = new byte[width * height]; TColor[] palette; - using (PixelAccessor pixels = image.Lock()) + using (PixelAccessor pixels = image.Lock()) { // Call the FirstPass function if not a single pass algorithm. // For something like an Octree quantizer, this will run through @@ -64,7 +62,7 @@ namespace ImageSharp.Quantizers this.SecondPass(pixels, quantizedPixels, width, height); } - return new QuantizedImage(width, height, palette, quantizedPixels); + return new QuantizedImage(width, height, palette, quantizedPixels); } /// @@ -73,7 +71,7 @@ namespace ImageSharp.Quantizers /// The source data /// The width in pixels of the image. /// The height in pixels of the image. - protected virtual void FirstPass(PixelAccessor source, int width, int height) + protected virtual void FirstPass(PixelAccessor source, int width, int height) { // Loop through each row for (int y = 0; y < height; y++) @@ -94,7 +92,7 @@ namespace ImageSharp.Quantizers /// The output pixel array /// The width in pixels of the image /// The height in pixels of the image - protected virtual void SecondPass(PixelAccessor source, byte[] output, int width, int height) + protected virtual void SecondPass(PixelAccessor source, byte[] output, int width, int height) { for (int y = 0; y < height; y++) { diff --git a/src/ImageSharp/Quantizers/Palette/PaletteQuantizer.cs b/src/ImageSharp/Quantizers/Palette/PaletteQuantizer.cs index ee19d8c2b..92e0ae3c6 100644 --- a/src/ImageSharp/Quantizers/Palette/PaletteQuantizer.cs +++ b/src/ImageSharp/Quantizers/Palette/PaletteQuantizer.cs @@ -14,10 +14,8 @@ namespace ImageSharp.Quantizers /// /// /// The pixel format. - /// The packed format. uint, long, float. - public class PaletteQuantizer : Quantizer - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class PaletteQuantizer : Quantizer + where TColor : struct, IPackedPixel, IEquatable { /// /// The pixel buffer, used to reduce allocations. @@ -27,7 +25,7 @@ namespace ImageSharp.Quantizers /// /// A lookup table for colors /// - private readonly Dictionary colorMap = new Dictionary(); + private readonly Dictionary colorMap = new Dictionary(); /// /// List of all colors in the palette @@ -35,7 +33,7 @@ namespace ImageSharp.Quantizers private TColor[] colors; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// The color palette. If none is given this will default to the web safe colors defined @@ -66,7 +64,7 @@ namespace ImageSharp.Quantizers } /// - public override QuantizedImage Quantize(ImageBase image, int maxColors) + public override QuantizedImage Quantize(ImageBase image, int maxColors) { Array.Resize(ref this.colors, maxColors.Clamp(1, 255)); return base.Quantize(image, maxColors); @@ -76,7 +74,7 @@ namespace ImageSharp.Quantizers protected override byte QuantizePixel(TColor pixel) { byte colorIndex = 0; - TPacked colorHash = pixel.PackedValue; + TColor colorHash = pixel; // Check if the color is in the lookup table if (this.colorMap.ContainsKey(colorHash)) diff --git a/src/ImageSharp/Quantizers/Quantize.cs b/src/ImageSharp/Quantizers/Quantize.cs index 93293a33b..f060f18b9 100644 --- a/src/ImageSharp/Quantizers/Quantize.cs +++ b/src/ImageSharp/Quantizers/Quantize.cs @@ -10,7 +10,7 @@ namespace ImageSharp using ImageSharp.Quantizers; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -18,28 +18,26 @@ namespace ImageSharp /// Applies quantization to the image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The quantization mode to apply to perform the operation. /// The maximum number of colors to return. Defaults to 256. - /// The . - public static Image Quantize(this Image source, Quantization mode = Quantization.Octree, int maxColors = 256) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image Quantize(this Image source, Quantization mode = Quantization.Octree, int maxColors = 256) + where TColor : struct, IPackedPixel, IEquatable { - IQuantizer quantizer; + IQuantizer quantizer; switch (mode) { case Quantization.Wu: - quantizer = new WuQuantizer(); + quantizer = new WuQuantizer(); break; case Quantization.Palette: - quantizer = new PaletteQuantizer(); + quantizer = new PaletteQuantizer(); break; default: - quantizer = new OctreeQuantizer(); + quantizer = new OctreeQuantizer(); break; } @@ -50,16 +48,14 @@ namespace ImageSharp /// Applies quantization to the image. /// /// The pixel format. - /// The packed format. uint, long, float. /// The image this method extends. /// The quantizer to apply to perform the operation. /// The maximum number of colors to return. - /// The . - public static Image Quantize(this Image source, IQuantizer quantizer, int maxColors) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + /// The . + public static Image Quantize(this Image source, IQuantizer quantizer, int maxColors) + where TColor : struct, IPackedPixel, IEquatable { - QuantizedImage quantizedImage = quantizer.Quantize(source, maxColors); + QuantizedImage quantizedImage = quantizer.Quantize(source, maxColors); source.SetPixels(source.Width, source.Height, quantizedImage.ToImage().Pixels); return source; } diff --git a/src/ImageSharp/Quantizers/QuantizedImage.cs b/src/ImageSharp/Quantizers/QuantizedImage.cs index 2f690012a..5ce53e71c 100644 --- a/src/ImageSharp/Quantizers/QuantizedImage.cs +++ b/src/ImageSharp/Quantizers/QuantizedImage.cs @@ -12,13 +12,11 @@ namespace ImageSharp.Quantizers /// Represents a quantized image where the pixels indexed by a color palette. /// /// The pixel format. - /// The packed format. uint, long, float. - public class QuantizedImage - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public class QuantizedImage + where TColor : struct, IPackedPixel, IEquatable { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The image width. /// The image height. @@ -68,9 +66,9 @@ namespace ImageSharp.Quantizers /// /// The /// - public Image ToImage() + public Image ToImage() { - Image image = new Image(); + Image image = new Image(); int pixelCount = this.Pixels.Length; int palletCount = this.Palette.Length - 1; diff --git a/src/ImageSharp/Quantizers/Wu/WuQuantizer.cs b/src/ImageSharp/Quantizers/Wu/WuQuantizer.cs index 47e41e84a..2b491ff4c 100644 --- a/src/ImageSharp/Quantizers/Wu/WuQuantizer.cs +++ b/src/ImageSharp/Quantizers/Wu/WuQuantizer.cs @@ -30,10 +30,8 @@ namespace ImageSharp.Quantizers /// /// /// The pixel format. - /// The packed format. uint, long, float. - public sealed class WuQuantizer : IQuantizer - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + public sealed class WuQuantizer : IQuantizer + where TColor : struct, IPackedPixel, IEquatable { /// /// The epsilon for comparing floating point numbers. @@ -121,11 +119,10 @@ namespace ImageSharp.Quantizers private readonly byte[] rgbaBuffer = new byte[4]; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// public WuQuantizer() { - // TODO: We might have to use a custom pool here. The default doesn't appear to save memory this.vwt = LongPool.Rent(TableLength); this.vmr = LongPool.Rent(TableLength); this.vmg = LongPool.Rent(TableLength); @@ -136,7 +133,7 @@ namespace ImageSharp.Quantizers } /// - public QuantizedImage Quantize(ImageBase image, int maxColors) + public QuantizedImage Quantize(ImageBase image, int maxColors) { Guard.NotNull(image, nameof(image)); @@ -144,7 +141,7 @@ namespace ImageSharp.Quantizers this.Clear(); - using (PixelAccessor imagePixels = image.Lock()) + using (PixelAccessor imagePixels = image.Lock()) { this.Build3DHistogram(imagePixels); this.Get3DMoments(); @@ -336,7 +333,7 @@ namespace ImageSharp.Quantizers /// Builds a 3-D color histogram of counts, r/g/b, c^2. /// /// The pixel accessor. - private void Build3DHistogram(PixelAccessor pixels) + private void Build3DHistogram(PixelAccessor pixels) { for (int y = 0; y < pixels.Height; y++) { @@ -752,7 +749,7 @@ namespace ImageSharp.Quantizers /// The color count. /// The cube. /// The result. - private QuantizedImage GenerateResult(PixelAccessor imagePixels, int colorCount, Box[] cube) + private QuantizedImage GenerateResult(PixelAccessor imagePixels, int colorCount, Box[] cube) { TColor[] pallette = new TColor[colorCount]; byte[] pixels = new byte[imagePixels.Width * imagePixels.Height]; @@ -783,24 +780,24 @@ namespace ImageSharp.Quantizers height, Bootstrapper.ParallelOptions, y => + { + byte[] rgba = ArrayPool.Shared.Rent(4); + for (int x = 0; x < width; x++) { - byte[] rgba = ArrayPool.Shared.Rent(4); - for (int x = 0; x < width; x++) - { - // Expected order r->g->b->a - imagePixels[x, y].ToBytes(rgba, 0, ComponentOrder.XYZW); + // Expected order r->g->b->a + imagePixels[x, y].ToBytes(rgba, 0, ComponentOrder.XYZW); - int r = rgba[0] >> (8 - IndexBits); - int g = rgba[1] >> (8 - IndexBits); - int b = rgba[2] >> (8 - IndexBits); - int a = rgba[3] >> (8 - IndexAlphaBits); + int r = rgba[0] >> (8 - IndexBits); + int g = rgba[1] >> (8 - IndexBits); + int b = rgba[2] >> (8 - IndexBits); + int a = rgba[3] >> (8 - IndexAlphaBits); - int ind = GetPaletteIndex(r + 1, g + 1, b + 1, a + 1); - pixels[(y * width) + x] = this.tag[ind]; - } + int ind = GetPaletteIndex(r + 1, g + 1, b + 1, a + 1); + pixels[(y * width) + x] = this.tag[ind]; + } - ArrayPool.Shared.Return(rgba); - }); + ArrayPool.Shared.Return(rgba); + }); // Cleanup LongPool.Return(this.vwt); @@ -811,7 +808,7 @@ namespace ImageSharp.Quantizers DoublePool.Return(this.m2); BytePool.Return(this.tag); - return new QuantizedImage(width, height, pallette, pixels); + return new QuantizedImage(width, height, pallette, pixels); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs b/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs index 59f006b46..1003aeaeb 100644 --- a/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs +++ b/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs @@ -19,8 +19,8 @@ namespace ImageSharp.Benchmarks.Image { CoreImage source = new CoreImage(1024, 768); CoreImage target = new CoreImage(1024, 768); - using (PixelAccessor sourcePixels = source.Lock()) - using (PixelAccessor targetPixels = target.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock()) { Parallel.For( 0, @@ -43,8 +43,8 @@ namespace ImageSharp.Benchmarks.Image { CoreImage source = new CoreImage(1024, 768); CoreImage target = new CoreImage(1024, 768); - using (PixelAccessor sourcePixels = source.Lock()) - using (PixelAccessor targetPixels = target.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock()) { Parallel.For( 0, diff --git a/tests/ImageSharp.Benchmarks/Image/GetSetPixel.cs b/tests/ImageSharp.Benchmarks/Image/GetSetPixel.cs index f48c730b1..d09531e75 100644 --- a/tests/ImageSharp.Benchmarks/Image/GetSetPixel.cs +++ b/tests/ImageSharp.Benchmarks/Image/GetSetPixel.cs @@ -29,7 +29,7 @@ namespace ImageSharp.Benchmarks.Image public CoreColor ResizeCore() { CoreImage image = new CoreImage(400, 400); - using (PixelAccessor imagePixels = image.Lock()) + using (PixelAccessor imagePixels = image.Lock()) { imagePixels[200, 200] = CoreColor.White; return imagePixels[200, 200]; diff --git a/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs b/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs index 89d6aa34a..5bb93a55c 100644 --- a/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs @@ -5,21 +5,20 @@ namespace ImageSharp.Tests.Drawing { - using Drawing; - using ImageSharp.Drawing; using System; - using System.Diagnostics.CodeAnalysis; using System.IO; - using System.Numerics; - using Xunit; + + using ImageSharp.Drawing; using ImageSharp.Drawing.Brushes; - public class FillPatternBrushTests: FileTestBase + using Xunit; + + public class FillPatternBrushTests : FileTestBase { - private Image Test(string name, Color background, IBrush brush, Color[,] expectedPattern) + private Image Test(string name, Color background, IBrush brush, Color[,] expectedPattern) { string path = CreateOutputDirectory("Fill", "PatternBrush"); - var image = new Image(20, 20); + Image image = new Image(20, 20); image .Fill(background) .Fill(brush); @@ -53,7 +52,7 @@ namespace ImageSharp.Tests.Drawing } using (FileStream output = File.OpenWrite($"{path}/{name}x4.png")) { - image.Resize(80,80).Save(output); + image.Resize(80, 80).Save(output); } @@ -69,13 +68,13 @@ namespace ImageSharp.Tests.Drawing { Color.LimeGreen, Color.LimeGreen, Color.LimeGreen, Color.LimeGreen}, { Color.LimeGreen, Color.LimeGreen, Color.HotPink , Color.LimeGreen}, { Color.LimeGreen, Color.LimeGreen, Color.LimeGreen, Color.LimeGreen} - }); + }); } [Fact] public void ImageShouldBeFloodFilledWithPercent10Transparent() { - Test("Percent10_Transparent", Color.Blue, Brushes.Percent10(Color.HotPink), + Test("Percent10_Transparent", Color.Blue, Brushes.Percent10(Color.HotPink), new Color[,] { { Color.HotPink , Color.Blue, Color.Blue, Color.Blue}, { Color.Blue, Color.Blue, Color.Blue, Color.Blue}, @@ -230,6 +229,6 @@ namespace ImageSharp.Tests.Drawing }); } - + } } diff --git a/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs b/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs index 850801e0e..9ead4cf56 100644 --- a/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs +++ b/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs @@ -54,39 +54,22 @@ namespace ImageSharp.Tests { Image image = file.CreateImage(); - //var image = file.CreateImage() - // .To() - // .To() - // .To() - // .To() - // .To() - // .To() - // .To() - // .To() - // .To() - // .To() - // .To() - // .To() - // .To() - // .To() - // .To(); - - // Image image = file.CreateImage().To(); - // Image image = file.CreateImage().To(); - // Image image = file.CreateImage().To(); - // Image image = file.CreateImage().To(); - // Image image = file.CreateImage().To(); - // Image image = file.CreateImage().To(); - // Image image = file.CreateImage().To(); - // Image image = file.CreateImage().To(); - // Image image = file.CreateImage().To(); - // Image image = file.CreateImage().To(); - // Image image = file.CreateImage().To(); - // Image image = file.CreateImage().To(); - // Image image = file.CreateImage().To(); - // Image image = file.CreateImage().To(); - // Image image = file.CreateImage().To(); - // Image image = file.CreateImage().To(); + //Image image = file.CreateImage().To(); + //Image image = file.CreateImage().To(); + //Image image = file.CreateImage().To(); + //Image image = file.CreateImage().To(); + //Image image = file.CreateImage().To(); + //Image image = file.CreateImage().To(); + //Image image = file.CreateImage().To(); + //Image image = file.CreateImage().To(); + //Image image = file.CreateImage().To(); + //Image image = file.CreateImage().To(); + //Image image = file.CreateImage().To(); + //Image image = file.CreateImage().To(); + //Image image = file.CreateImage().To(); + //Image image = file.CreateImage().To(); + //Image image = file.CreateImage().To(); + //Image image = file.CreateImage().To(); using (FileStream output = File.OpenWrite($"{path}/{file.FileName}")) { image.Save(output); diff --git a/tests/ImageSharp.Tests/Image/ImageTests.cs b/tests/ImageSharp.Tests/Image/ImageTests.cs index 2dd73a0b5..5a5348d00 100644 --- a/tests/ImageSharp.Tests/Image/ImageTests.cs +++ b/tests/ImageSharp.Tests/Image/ImageTests.cs @@ -5,28 +5,28 @@ namespace ImageSharp.Tests { - using System; + using System; - using Xunit; + using Xunit; - /// - /// Tests the class. - /// - public class ImageTests - { - [Fact] - public void ConstructorByteArray() + /// + /// Tests the class. + /// + public class ImageTests { - Assert.Throws(() => - { - new Image((byte[])null); - }); + [Fact] + public void ConstructorByteArray() + { + Assert.Throws(() => + { + new Image((byte[])null); + }); - TestFile file = TestImages.Bmp.Car; - var image = new Image(file.Bytes); + TestFile file = TestImages.Bmp.Car; + Image image = new Image(file.Bytes); - Assert.Equal(600, image.Width); - Assert.Equal(450, image.Height); + Assert.Equal(600, image.Width); + Assert.Equal(450, image.Height); + } } - } } diff --git a/tests/ImageSharp.Tests/Image/PixelAccessorTests.cs b/tests/ImageSharp.Tests/Image/PixelAccessorTests.cs index e5c051264..e47678d0c 100644 --- a/tests/ImageSharp.Tests/Image/PixelAccessorTests.cs +++ b/tests/ImageSharp.Tests/Image/PixelAccessorTests.cs @@ -17,7 +17,7 @@ namespace ImageSharp.Tests [Fact] public void CopyFromZYX() { - CopyFromZYX(new Image(1, 1)); + CopyFromZYX(new Image(1, 1)); } [Fact] @@ -29,7 +29,7 @@ namespace ImageSharp.Tests [Fact] public void CopyFromZYXW() { - CopyFromZYXW(new Image(1, 1)); + CopyFromZYXW(new Image(1, 1)); } [Fact] @@ -41,7 +41,7 @@ namespace ImageSharp.Tests [Fact] public void CopyToZYX() { - CopyToZYX(new Image(1, 1)); + CopyToZYX(new Image(1, 1)); } [Fact] @@ -53,7 +53,7 @@ namespace ImageSharp.Tests [Fact] public void CopyToZYXW() { - CopyToZYXW(new Image(1, 1)); + CopyToZYXW(new Image(1, 1)); } [Fact] @@ -62,18 +62,17 @@ namespace ImageSharp.Tests CopyToZYXW(new Image(1, 1)); } - private static void CopyFromZYX(Image image) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private static void CopyFromZYX(Image image) + where TColor : struct, IPackedPixel, IEquatable { - using (PixelAccessor pixels = image.Lock()) + using (PixelAccessor pixels = image.Lock()) { byte red = 1; byte green = 2; byte blue = 3; byte alpha = 255; - using (PixelArea row = new PixelArea(1, ComponentOrder.ZYX)) + using (PixelArea row = new PixelArea(1, ComponentOrder.ZYX)) { row.Bytes[0] = blue; row.Bytes[1] = green; @@ -90,18 +89,17 @@ namespace ImageSharp.Tests } } - private static void CopyFromZYXW(Image image) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private static void CopyFromZYXW(Image image) + where TColor : struct, IPackedPixel, IEquatable { - using (PixelAccessor pixels = image.Lock()) + using (PixelAccessor pixels = image.Lock()) { byte red = 1; byte green = 2; byte blue = 3; byte alpha = 4; - using (PixelArea row = new PixelArea(1, ComponentOrder.ZYXW)) + using (PixelArea row = new PixelArea(1, ComponentOrder.ZYXW)) { row.Bytes[0] = blue; row.Bytes[1] = green; @@ -119,17 +117,16 @@ namespace ImageSharp.Tests } } - private static void CopyToZYX(Image image) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private static void CopyToZYX(Image image) + where TColor : struct, IPackedPixel, IEquatable { - using (PixelAccessor pixels = image.Lock()) + using (PixelAccessor pixels = image.Lock()) { byte red = 1; byte green = 2; byte blue = 3; - using (PixelArea row = new PixelArea(1, ComponentOrder.ZYX)) + using (PixelArea row = new PixelArea(1, ComponentOrder.ZYX)) { pixels[0, 0] = (TColor)(object)new Color(red, green, blue); @@ -142,18 +139,17 @@ namespace ImageSharp.Tests } } - private static void CopyToZYXW(Image image) - where TColor : struct, IPackedPixel - where TPacked : struct, IEquatable + private static void CopyToZYXW(Image image) + where TColor : struct, IPackedPixel, IEquatable { - using (PixelAccessor pixels = image.Lock()) + using (PixelAccessor pixels = image.Lock()) { byte red = 1; byte green = 2; byte blue = 3; byte alpha = 4; - using (PixelArea row = new PixelArea(1, ComponentOrder.ZYXW)) + using (PixelArea row = new PixelArea(1, ComponentOrder.ZYXW)) { pixels[0, 0] = (TColor)(object)new Color(red, green, blue, alpha); diff --git a/tests/ImageSharp.Tests/Processors/Filters/OilPaintTest.cs b/tests/ImageSharp.Tests/Processors/Filters/OilPaintTest.cs index 970d79a5a..c177e9423 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/OilPaintTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/OilPaintTest.cs @@ -52,11 +52,11 @@ namespace ImageSharp.Tests string filename = file.GetFileName(value + "-InBox"); Image image = file.CreateImage(); - using (FileStream output = File.OpenWrite($"{path}/{filename}")) + if (image.Width > value.Item2 && image.Height > value.Item2) { - if (image.Width > value.Item2 && image.Height > value.Item2) + using (FileStream output = File.OpenWrite($"{path}/{filename}")) { - image.OilPaint(value.Item1, value.Item2, new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output); + image.OilPaint(value.Item1, value.Item2, new Rectangle(image.Width / 4, image.Width / 4, image.Width / 2, image.Height / 2)).Save(output); } } } diff --git a/tests/ImageSharp.Tests/Profiles/Exif/ExifProfileTests.cs b/tests/ImageSharp.Tests/Profiles/Exif/ExifProfileTests.cs index 794d1a489..fca903605 100644 --- a/tests/ImageSharp.Tests/Profiles/Exif/ExifProfileTests.cs +++ b/tests/ImageSharp.Tests/Profiles/Exif/ExifProfileTests.cs @@ -207,7 +207,7 @@ namespace ImageSharp.Tests TestProfile(profile); - var thumbnail = profile.CreateThumbnail(); + var thumbnail = profile.CreateThumbnail(); Assert.NotNull(thumbnail); Assert.Equal(256, thumbnail.Width); Assert.Equal(170, thumbnail.Height); @@ -218,7 +218,9 @@ namespace ImageSharp.Tests { StringBuilder junk = new StringBuilder(); for (int i = 0; i < 65500; i++) + { junk.Append("I"); + } Image image = new Image(100, 100); image.ExifProfile = new ExifProfile();