diff --git a/README.md b/README.md index 699108cbbf..8a6ccd08c5 100644 --- a/README.md +++ b/README.md @@ -182,7 +182,7 @@ Individual processors can be initialised and apply processing against images. Th new Brightness(50).Apply(sourceImage, targetImage, sourceImage.Bounds); ``` -For advanced usage the `Image` class is 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` class is 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/ImageProcessorCore/Bootstrapper.cs b/src/ImageProcessorCore/Bootstrapper.cs index 99fa6f1555..9e5ec39fd3 100644 --- a/src/ImageProcessorCore/Bootstrapper.cs +++ b/src/ImageProcessorCore/Bootstrapper.cs @@ -29,8 +29,6 @@ namespace ImageProcessorCore /// private readonly List imageFormats; - private readonly Dictionary> pixelAccessors; - /// /// Prevents a default instance of the class from being created. /// @@ -43,11 +41,6 @@ namespace ImageProcessorCore new PngFormat(), new GifFormat() }; - - this.pixelAccessors = new Dictionary> - { - { typeof(Color), i=> new ColorPixelAccessor(i) } - }; } /// @@ -61,12 +54,6 @@ namespace ImageProcessorCore public IReadOnlyCollection ImageFormats => new ReadOnlyCollection(this.imageFormats); - /// - /// Gets the collection of supported pixel accessors - /// - public IReadOnlyDictionary> PixelAccessors => - new ReadOnlyDictionary>(this.pixelAccessors); - /// /// Gets or sets the global parallel options for processing tasks in parallel. /// @@ -80,40 +67,5 @@ namespace ImageProcessorCore { this.imageFormats.Add(format); } - - /// - /// Adds a pixel accessor for the given pixel format. - /// - /// The packed format type, must implement - /// The function to return a new instance of the pixel accessor. - public void AddPixelAccessor(Type packedType, Func initializer) - { - if (!typeof(IPackedVector).GetTypeInfo().IsAssignableFrom(packedType.GetTypeInfo())) - { - throw new ArgumentException($"Type {packedType} must implement {nameof(IPackedVector)}"); - } - - this.pixelAccessors.Add(packedType, initializer); - } - - /// - /// Gets an instance of the correct for the packed vector. - /// - /// The type of pixel data. - /// The packed format. long, float. - /// The image - /// The - public IPixelAccessor GetPixelAccessor(IImageBase image) - where T : IPackedVector - where TP : struct - { - Type packed = typeof(T); - if (this.pixelAccessors.ContainsKey(packed)) - { - return (IPixelAccessor)this.pixelAccessors[packed].Invoke(image); - } - - throw new NotSupportedException($"PixelAccessor cannot be loaded for {packed}:"); - } } } diff --git a/src/ImageProcessorCore/Colors/Colorspaces/IAlmostEquatable.cs b/src/ImageProcessorCore/Colors/Colorspaces/IAlmostEquatable.cs index 4677c3415f..97f57c21a0 100644 --- a/src/ImageProcessorCore/Colors/Colorspaces/IAlmostEquatable.cs +++ b/src/ImageProcessorCore/Colors/Colorspaces/IAlmostEquatable.cs @@ -11,9 +11,9 @@ namespace ImageProcessorCore /// Defines a generalized method that a value type or class implements to create /// a type-specific method for determining approximate equality of instances. /// - /// The type of objects to compare. - /// The object specifying the type to specify precision with. - public interface IAlmostEquatable where TP : struct, IComparable + /// The type of objects to compare. + /// The object specifying the type to specify precision with. + public interface IAlmostEquatable where TPacked : struct, IComparable { /// /// Indicates whether the current object is equal to another object of the same type @@ -24,6 +24,6 @@ namespace ImageProcessorCore /// /// true if the current object is equal to the other parameter; otherwise, false. /// - bool AlmostEquals(T other, TP precision); + bool AlmostEquals(TColor other, TPacked precision); } } diff --git a/src/ImageProcessorCore/Colors/PackedVector/IPackedVector.cs b/src/ImageProcessorCore/Colors/PackedVector/IPackedVector.cs index 05b593e67e..114a173eb0 100644 --- a/src/ImageProcessorCore/Colors/PackedVector/IPackedVector.cs +++ b/src/ImageProcessorCore/Colors/PackedVector/IPackedVector.cs @@ -11,25 +11,25 @@ namespace ImageProcessorCore /// An interface that converts packed vector types to and from values, /// allowing multiple encodings to be manipulated in a generic manner. /// - /// The packed format. long, float. - public interface IPackedVector : IPackedVector - where TP : struct + /// The packed format. uint, long, float. + public interface IPackedVector : IPackedVector + where TPacked : struct { /// /// Directly gets the packed representation of the packed vector. /// Typically packed in least to greatest significance order. /// /// - /// The . + /// The . /// - TP GetPackedValue(); + TPacked GetPackedValue(); /// /// Directly sets the packed representation of the packed vector. /// Typically packed in least to greatest significance order. /// /// The packed value. - void SetPackedValue(TP value); + void SetPackedValue(TPacked value); } /// diff --git a/src/ImageProcessorCore/Common/Extensions/ByteExtensions.cs b/src/ImageProcessorCore/Common/Extensions/ByteExtensions.cs index 05b71bb2f6..bee549c0f9 100644 --- a/src/ImageProcessorCore/Common/Extensions/ByteExtensions.cs +++ b/src/ImageProcessorCore/Common/Extensions/ByteExtensions.cs @@ -19,7 +19,7 @@ namespace ImageProcessorCore /// The bytes to convert from. Cannot be null. /// The number of bits per value. /// The resulting array. Is never null. - /// is null. + /// is null. /// is less than or equals than zero. public static byte[] ToArrayByBitsLength(this byte[] bytes, int bits) { diff --git a/src/ImageProcessorCore/Common/Helpers/Guard.cs b/src/ImageProcessorCore/Common/Helpers/Guard.cs index d11addf2a0..6940a460e4 100644 --- a/src/ImageProcessorCore/Common/Helpers/Guard.cs +++ b/src/ImageProcessorCore/Common/Helpers/Guard.cs @@ -35,7 +35,7 @@ namespace ImageProcessorCore /// /// The error message, if any to add to the exception. /// - /// + /// /// is null /// public static void NotNull(object target, string parameterName, string message = "") @@ -58,7 +58,7 @@ namespace ImageProcessorCore /// /// The target string, which should be checked against being null or empty. /// Name of the parameter. - /// + /// /// is null. /// /// diff --git a/src/ImageProcessorCore/Common/Helpers/ImageMaths.cs b/src/ImageProcessorCore/Common/Helpers/ImageMaths.cs index 9b890d1c0b..f356841395 100644 --- a/src/ImageProcessorCore/Common/Helpers/ImageMaths.cs +++ b/src/ImageProcessorCore/Common/Helpers/ImageMaths.cs @@ -156,17 +156,17 @@ namespace ImageProcessorCore /// Finds the bounding rectangle based on the first instance of any color component other /// than the given one. /// - /// The pixel format. - /// The packed format. long, float. + /// The 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 T : IPackedVector - where TP : struct + public static Rectangle GetFilteredBoundingRectangle(ImageBase bitmap, float componentValue, RgbaComponent channel = RgbaComponent.B) + where TColor : IPackedVector + where TPacked : struct { const float Epsilon = .00001f; int width = bitmap.Width; @@ -174,7 +174,7 @@ namespace ImageProcessorCore Point topLeft = new Point(); Point bottomRight = new Point(); - Func, int, int, float, bool> delegateFunc; + Func, int, int, float, bool> delegateFunc; // Determine which channel to check against switch (channel) @@ -196,7 +196,7 @@ namespace ImageProcessorCore break; } - Func, int> getMinY = pixels => + Func, int> getMinY = pixels => { for (int y = 0; y < height; y++) { @@ -212,7 +212,7 @@ namespace ImageProcessorCore return 0; }; - Func, int> getMaxY = pixels => + Func, int> getMaxY = pixels => { for (int y = height - 1; y > -1; y--) { @@ -228,7 +228,7 @@ namespace ImageProcessorCore return height; }; - Func, int> getMinX = pixels => + Func, int> getMinX = pixels => { for (int x = 0; x < width; x++) { @@ -244,7 +244,7 @@ namespace ImageProcessorCore return 0; }; - Func, int> getMaxX = pixels => + Func, int> getMaxX = pixels => { for (int x = width - 1; x > -1; x--) { @@ -260,7 +260,7 @@ namespace ImageProcessorCore return height; }; - using (IPixelAccessor bitmapPixels = bitmap.Lock()) + using (PixelAccessor bitmapPixels = bitmap.Lock()) { topLeft.Y = getMinY(bitmapPixels); topLeft.X = getMinX(bitmapPixels); diff --git a/src/ImageProcessorCore/Filters/Alpha.cs b/src/ImageProcessorCore/Filters/Alpha.cs index 545639afa0..1d678370df 100644 --- a/src/ImageProcessorCore/Filters/Alpha.cs +++ b/src/ImageProcessorCore/Filters/Alpha.cs @@ -15,15 +15,15 @@ namespace ImageProcessorCore /// /// Alters the alpha component of the image. /// - /// The pixel format. - /// The packed format. long, float. + /// 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. /// A delegate which is called as progress is made processing the image. - /// The . - public static Image Alpha(this Image source, int percent, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image Alpha(this Image source, int percent, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { return Alpha(source, percent, source.Bounds, progressHandler); } @@ -31,8 +31,8 @@ namespace ImageProcessorCore /// /// Alters the alpha component of the image. /// - /// The pixel format. - /// The packed format. long, float. + /// 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. /// @@ -40,11 +40,11 @@ namespace ImageProcessorCore /// /// A delegate which is called as progress is made processing the image. /// The . - public static Image Alpha(this Image source, int percent, Rectangle rectangle, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + public static Image Alpha(this Image source, int percent, Rectangle rectangle, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { - AlphaProcessor processor = new AlphaProcessor(percent); + AlphaProcessor processor = new AlphaProcessor(percent); processor.OnProgress += progressHandler; try diff --git a/src/ImageProcessorCore/Filters/BackgroundColor.cs b/src/ImageProcessorCore/Filters/BackgroundColor.cs index 44f46598b5..f059700e11 100644 --- a/src/ImageProcessorCore/Filters/BackgroundColor.cs +++ b/src/ImageProcessorCore/Filters/BackgroundColor.cs @@ -8,24 +8,24 @@ namespace ImageProcessorCore using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Replaces the background color of image with the given one. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image this method extends. /// The color to set as the background. /// A delegate which is called as progress is made processing the image. - /// The . - public static Image BackgroundColor(this Image source, T color, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image BackgroundColor(this Image source, TColor color, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { - BackgroundColorProcessor processor = new BackgroundColorProcessor(color); + BackgroundColorProcessor processor = new BackgroundColorProcessor(color); processor.OnProgress += progressHandler; try diff --git a/src/ImageProcessorCore/Filters/BinaryThreshold.cs b/src/ImageProcessorCore/Filters/BinaryThreshold.cs index 5d244ead4d..b57d63c4f5 100644 --- a/src/ImageProcessorCore/Filters/BinaryThreshold.cs +++ b/src/ImageProcessorCore/Filters/BinaryThreshold.cs @@ -8,22 +8,22 @@ namespace ImageProcessorCore 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. /// - /// The pixel format. - /// The packed format. long, float. + /// 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. /// A delegate which is called as progress is made processing the image. - /// The . - public static Image BinaryThreshold(this Image source, float threshold, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image BinaryThreshold(this Image source, float threshold, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { return BinaryThreshold(source, threshold, source.Bounds, progressHandler); } @@ -31,20 +31,20 @@ namespace ImageProcessorCore /// /// Applies binerization to the image splitting the pixels at the given threshold. /// - /// The pixel format. - /// The packed format. long, float. + /// 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 structure that specifies the portion of the image object to alter. /// /// A delegate which is called as progress is made processing the image. - /// The . - public static Image BinaryThreshold(this Image source, float threshold, Rectangle rectangle, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image BinaryThreshold(this Image source, float threshold, Rectangle rectangle, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { - BinaryThresholdProcessor processor = new BinaryThresholdProcessor(threshold); + BinaryThresholdProcessor processor = new BinaryThresholdProcessor(threshold); processor.OnProgress += progressHandler; try diff --git a/src/ImageProcessorCore/Filters/BlackWhite.cs b/src/ImageProcessorCore/Filters/BlackWhite.cs index 8799cfe64f..2093873083 100644 --- a/src/ImageProcessorCore/Filters/BlackWhite.cs +++ b/src/ImageProcessorCore/Filters/BlackWhite.cs @@ -8,21 +8,21 @@ namespace ImageProcessorCore using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Applies black and white toning to the image. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image this method extends. /// A delegate which is called as progress is made processing the image. - /// The . - public static Image BlackWhite(this Image source, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image BlackWhite(this Image source, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { return BlackWhite(source, source.Bounds, progressHandler); } @@ -30,19 +30,19 @@ namespace ImageProcessorCore /// /// Applies black and white toning to the image. /// - /// The pixel format. - /// The packed format. long, float. + /// 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. /// /// A delegate which is called as progress is made processing the image. - /// The . - public static Image BlackWhite(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image BlackWhite(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { - BlackWhiteProcessor processor = new BlackWhiteProcessor(); + BlackWhiteProcessor processor = new BlackWhiteProcessor(); processor.OnProgress += progressHandler; try diff --git a/src/ImageProcessorCore/Filters/Blend.cs b/src/ImageProcessorCore/Filters/Blend.cs index 96f8f60cda..77b65cf200 100644 --- a/src/ImageProcessorCore/Filters/Blend.cs +++ b/src/ImageProcessorCore/Filters/Blend.cs @@ -17,14 +17,14 @@ namespace ImageProcessorCore /// /// The image this method extends. /// The image to blend with the currently processing image. - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The opacity of the image image to blend. Must be between 0 and 100. /// A delegate which is called as progress is made processing the image. - /// The . - public static Image Blend(this Image source, ImageBase image, int percent = 50, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image Blend(this Image source, ImageBase image, int percent = 50, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { return Blend(source, image, percent, source.Bounds, progressHandler); } @@ -34,19 +34,19 @@ namespace ImageProcessorCore /// /// The image this method extends. /// The image to blend with the currently processing image. - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The opacity of the image image to blend. Must be between 0 and 100. /// /// The structure that specifies the portion of the image object to alter. /// /// A delegate which is called as progress is made processing the image. - /// The . - public static Image Blend(this Image source, ImageBase image, int percent, Rectangle rectangle, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image Blend(this Image source, ImageBase image, int percent, Rectangle rectangle, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { - BlendProcessor processor = new BlendProcessor(image, percent); + BlendProcessor processor = new BlendProcessor(image, percent); processor.OnProgress += progressHandler; try diff --git a/src/ImageProcessorCore/Filters/BoxBlur.cs b/src/ImageProcessorCore/Filters/BoxBlur.cs index e1970228f3..acbd0d8959 100644 --- a/src/ImageProcessorCore/Filters/BoxBlur.cs +++ b/src/ImageProcessorCore/Filters/BoxBlur.cs @@ -8,22 +8,22 @@ namespace ImageProcessorCore using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Applies a box blur to the image. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image this method extends. /// The 'radius' value representing the size of the area to sample. /// A delegate which is called as progress is made processing the image. - /// The . - public static Image BoxBlur(this Image source, int radius = 7, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image BoxBlur(this Image source, int radius = 7, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { return BoxBlur(source, radius, source.Bounds, progressHandler); } @@ -31,20 +31,20 @@ namespace ImageProcessorCore /// /// Applies a box blur to the image. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image this method extends. /// The 'radius' value representing the size of the area to sample. /// /// The structure that specifies the portion of the image object to alter. /// /// A delegate which is called as progress is made processing the image. - /// The . - public static Image BoxBlur(this Image source, int radius, Rectangle rectangle, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image BoxBlur(this Image source, int radius, Rectangle rectangle, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { - BoxBlurProcessor processor = new BoxBlurProcessor(radius); + BoxBlurProcessor processor = new BoxBlurProcessor(radius); processor.OnProgress += progressHandler; try diff --git a/src/ImageProcessorCore/Filters/Brightness.cs b/src/ImageProcessorCore/Filters/Brightness.cs index fb29ff0d9c..82738c7f4a 100644 --- a/src/ImageProcessorCore/Filters/Brightness.cs +++ b/src/ImageProcessorCore/Filters/Brightness.cs @@ -8,22 +8,21 @@ namespace ImageProcessorCore using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Alters the brightness component of the image. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. /// The image this method extends. /// The new brightness of the image. Must be between -100 and 100. /// A delegate which is called as progress is made processing the image. - /// The . - public static Image Brightness(this Image source, int amount, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image Brightness(this Image source, int amount, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { return Brightness(source, amount, source.Bounds, progressHandler); } @@ -31,20 +30,19 @@ namespace ImageProcessorCore /// /// Alters the brightness component of the image. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. /// The image this method extends. /// The new brightness of the image. Must be between -100 and 100. /// /// The structure that specifies the portion of the image object to alter. /// /// A delegate which is called as progress is made processing the image. - /// The . - public static Image Brightness(this Image source, int amount, Rectangle rectangle, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image Brightness(this Image source, int amount, Rectangle rectangle, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { - BrightnessProcessor processor = new BrightnessProcessor(amount); + BrightnessProcessor processor = new BrightnessProcessor(amount); processor.OnProgress += progressHandler; try diff --git a/src/ImageProcessorCore/Filters/ColorBlindness.cs b/src/ImageProcessorCore/Filters/ColorBlindness.cs index 6ab553ba2d..462e0e8ff6 100644 --- a/src/ImageProcessorCore/Filters/ColorBlindness.cs +++ b/src/ImageProcessorCore/Filters/ColorBlindness.cs @@ -8,22 +8,22 @@ namespace ImageProcessorCore using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Applies the given colorblindness simulator to the image. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image this method extends. /// The type of color blindness simulator to apply. /// A delegate which is called as progress is made processing the image. - /// The . - public static Image ColorBlindness(this Image source, ColorBlindness colorBlindness, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image ColorBlindness(this Image source, ColorBlindness colorBlindness, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { return ColorBlindness(source, colorBlindness, source.Bounds, progressHandler); } @@ -31,53 +31,53 @@ namespace ImageProcessorCore /// /// Applies the given colorblindness simulator to the image. /// - /// The pixel format. - /// The packed format. long, float. + /// 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. /// /// A delegate which is called as progress is made processing the image. - /// The . - public static Image ColorBlindness(this Image source, ColorBlindness colorBlindness, Rectangle rectangle, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image ColorBlindness(this Image source, ColorBlindness colorBlindness, Rectangle rectangle, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { - IImageProcessor processor; + IImageProcessor processor; switch (colorBlindness) { case ImageProcessorCore.ColorBlindness.Achromatomaly: - processor = new AchromatomalyProcessor(); + processor = new AchromatomalyProcessor(); break; case ImageProcessorCore.ColorBlindness.Achromatopsia: - processor = new AchromatopsiaProcessor(); + processor = new AchromatopsiaProcessor(); break; case ImageProcessorCore.ColorBlindness.Deuteranomaly: - processor = new DeuteranomalyProcessor(); + processor = new DeuteranomalyProcessor(); break; case ImageProcessorCore.ColorBlindness.Deuteranopia: - processor = new DeuteranopiaProcessor(); + processor = new DeuteranopiaProcessor(); break; case ImageProcessorCore.ColorBlindness.Protanomaly: - processor = new ProtanomalyProcessor(); + processor = new ProtanomalyProcessor(); break; case ImageProcessorCore.ColorBlindness.Protanopia: - processor = new ProtanopiaProcessor(); + processor = new ProtanopiaProcessor(); break; case ImageProcessorCore.ColorBlindness.Tritanomaly: - processor = new TritanomalyProcessor(); + processor = new TritanomalyProcessor(); break; default: - processor = new TritanopiaProcessor(); + processor = new TritanopiaProcessor(); break; } diff --git a/src/ImageProcessorCore/Filters/Contrast.cs b/src/ImageProcessorCore/Filters/Contrast.cs index 5025daf641..364fc34b48 100644 --- a/src/ImageProcessorCore/Filters/Contrast.cs +++ b/src/ImageProcessorCore/Filters/Contrast.cs @@ -8,22 +8,22 @@ namespace ImageProcessorCore using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Alters the contrast component of the image. /// - /// The pixel format. - /// The packed format. long, float. + /// The 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. /// A delegate which is called as progress is made processing the image. - /// The . - public static Image Contrast(this Image source, int amount, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image Contrast(this Image source, int amount, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { return Contrast(source, amount, source.Bounds, progressHandler); } @@ -31,20 +31,20 @@ namespace ImageProcessorCore /// /// Alters the contrast component of the image. /// - /// The pixel format. - /// The packed format. long, float. + /// 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. /// /// A delegate which is called as progress is made processing the image. - /// The . - public static Image Contrast(this Image source, int amount, Rectangle rectangle, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image Contrast(this Image source, int amount, Rectangle rectangle, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { - ContrastProcessor processor = new ContrastProcessor(amount); + ContrastProcessor processor = new ContrastProcessor(amount); processor.OnProgress += progressHandler; try diff --git a/src/ImageProcessorCore/Filters/DetectEdges.cs b/src/ImageProcessorCore/Filters/DetectEdges.cs index c4cee3b23f..9e906fcf77 100644 --- a/src/ImageProcessorCore/Filters/DetectEdges.cs +++ b/src/ImageProcessorCore/Filters/DetectEdges.cs @@ -8,58 +8,58 @@ namespace ImageProcessorCore using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// - /// Detects any edges within the image. Uses the filter + /// Detects any edges within the image. Uses the filter /// operating in Grayscale mode. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image this method extends. /// A delegate which is called as progress is made processing the image. - /// The . - public static Image DetectEdges(this Image source, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image DetectEdges(this Image source, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { - return DetectEdges(source, source.Bounds, new SobelProcessor { Grayscale = true }, progressHandler); + return DetectEdges(source, source.Bounds, new SobelProcessor { Grayscale = true }, progressHandler); } /// - /// 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. long, float. + /// 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. /// /// A delegate which is called as progress is made processing the image. - /// The . - public static Image DetectEdges(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image DetectEdges(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { - return DetectEdges(source, rectangle, new SobelProcessor { Grayscale = true }, progressHandler); + return DetectEdges(source, rectangle, new SobelProcessor { Grayscale = true }, progressHandler); } /// /// Detects any edges within the image. /// - /// The pixel format. - /// The packed format. long, float. + /// 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. /// A delegate which is called as progress is made processing the image. - /// The . - public static Image DetectEdges(this Image source, EdgeDetection filter, bool grayscale = true, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image DetectEdges(this Image source, EdgeDetection filter, bool grayscale = true, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { return DetectEdges(source, filter, source.Bounds, grayscale, progressHandler); } @@ -67,8 +67,8 @@ namespace ImageProcessorCore /// /// Detects any edges within the image. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image this method extends. /// The filter for detecting edges. /// @@ -76,49 +76,49 @@ namespace ImageProcessorCore /// /// Whether to convert the image to Grayscale first. Defaults to true. /// A delegate which is called as progress is made processing the image. - /// The . - public static Image DetectEdges(this Image source, EdgeDetection filter, Rectangle rectangle, bool grayscale = true, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image DetectEdges(this Image source, EdgeDetection filter, Rectangle rectangle, bool grayscale = true, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { - IEdgeDetectorFilter processor; + IEdgeDetectorFilter 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.Scharr: - processor = new ScharrProcessor { Grayscale = grayscale }; + processor = new ScharrProcessor { Grayscale = grayscale }; break; default: - processor = new ScharrProcessor { Grayscale = grayscale }; + processor = new ScharrProcessor { Grayscale = grayscale }; break; } @@ -128,15 +128,15 @@ namespace ImageProcessorCore /// /// Detects any edges within the image. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image this method extends. /// The filter for detecting edges. /// A delegate which is called as progress is made processing the image. - /// The . - public static Image DetectEdges(this Image source, IEdgeDetectorFilter filter, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image DetectEdges(this Image source, IEdgeDetectorFilter filter, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { return DetectEdges(source, source.Bounds, filter, progressHandler); } @@ -144,18 +144,18 @@ namespace ImageProcessorCore /// /// Detects any edges within the image. /// - /// The pixel format. - /// The packed format. long, float. + /// 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. /// A delegate which is called as progress is made processing the image. - /// The . - public static Image DetectEdges(this Image source, Rectangle rectangle, IEdgeDetectorFilter filter, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image DetectEdges(this Image source, Rectangle rectangle, IEdgeDetectorFilter filter, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { filter.OnProgress += progressHandler; diff --git a/src/ImageProcessorCore/Filters/Glow.cs b/src/ImageProcessorCore/Filters/Glow.cs index 49acf33425..0d5b18fb35 100644 --- a/src/ImageProcessorCore/Filters/Glow.cs +++ b/src/ImageProcessorCore/Filters/Glow.cs @@ -8,37 +8,37 @@ namespace ImageProcessorCore using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Applies a radial glow effect to an image. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image this method extends. /// A delegate which is called as progress is made processing the image. - /// The . - public static Image Glow(this Image source, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image Glow(this Image source, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { - return Glow(source, default(T), source.Bounds.Width * .5F, source.Bounds, progressHandler); + return Glow(source, default(TColor), source.Bounds.Width * .5F, source.Bounds, progressHandler); } /// /// Applies a radial glow effect to an image. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image this method extends. /// The color to set as the glow. /// A delegate which is called as progress is made processing the image. - /// The . - public static Image Glow(this Image source, T color, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image Glow(this Image source, TColor color, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { return Glow(source, color, source.Bounds.Width * .5F, source.Bounds, progressHandler); } @@ -46,42 +46,42 @@ namespace ImageProcessorCore /// /// Applies a radial glow effect to an image. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image this method extends. /// The the radius. /// A delegate which is called as progress is made processing the image. - /// The . - public static Image Glow(this Image source, float radius, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image Glow(this Image source, float radius, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { - return Glow(source, default(T), radius, source.Bounds, progressHandler); + return Glow(source, default(TColor), radius, source.Bounds, progressHandler); } /// /// Applies a radial glow effect to an image. /// - /// The pixel format. - /// The packed format. long, float. + /// 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. /// /// A delegate which is called as progress is made processing the image. - /// The . - public static Image Glow(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image Glow(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { - return Glow(source, default(T), 0, rectangle, progressHandler); + return Glow(source, default(TColor), 0, rectangle, progressHandler); } /// /// Applies a radial glow effect to an image. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image this method extends. /// The color to set as the glow. /// The the radius. @@ -89,14 +89,14 @@ namespace ImageProcessorCore /// The structure that specifies the portion of the image object to alter. /// /// A delegate which is called as progress is made processing the image. - /// The . - public static Image Glow(this Image source, T color, float radius, Rectangle rectangle, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image Glow(this Image source, TColor color, float radius, Rectangle rectangle, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { - GlowProcessor processor = new GlowProcessor { Radius = radius, }; + GlowProcessor processor = new GlowProcessor { Radius = radius, }; - if (!color.Equals(default(T))) + if (!color.Equals(default(TColor))) { processor.GlowColor = color; } diff --git a/src/ImageProcessorCore/Filters/Grayscale.cs b/src/ImageProcessorCore/Filters/Grayscale.cs index 46ef445266..3d8b39e913 100644 --- a/src/ImageProcessorCore/Filters/Grayscale.cs +++ b/src/ImageProcessorCore/Filters/Grayscale.cs @@ -8,22 +8,22 @@ namespace ImageProcessorCore using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Applies Grayscale toning to the image. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image this method extends. /// The formula to apply to perform the operation. /// A delegate which is called as progress is made processing the image. - /// The . - public static Image Grayscale(this Image source, GrayscaleMode mode = GrayscaleMode.Bt709, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image Grayscale(this Image source, GrayscaleMode mode = GrayscaleMode.Bt709, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { return Grayscale(source, source.Bounds, mode, progressHandler); } @@ -31,22 +31,22 @@ namespace ImageProcessorCore /// /// Applies Grayscale toning to the image. /// - /// The pixel format. - /// The packed format. long, float. + /// 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. /// A delegate which is called as progress is made processing the image. - /// The . - public static Image Grayscale(this Image source, Rectangle rectangle, GrayscaleMode mode = GrayscaleMode.Bt709, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image Grayscale(this Image source, Rectangle rectangle, GrayscaleMode mode = GrayscaleMode.Bt709, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { - IImageProcessor processor = mode == GrayscaleMode.Bt709 - ? (IImageProcessor)new GrayscaleBt709Processor() - : new GrayscaleBt601Processor(); + IImageProcessor processor = mode == GrayscaleMode.Bt709 + ? (IImageProcessor)new GrayscaleBt709Processor() + : new GrayscaleBt601Processor(); processor.OnProgress += progressHandler; diff --git a/src/ImageProcessorCore/Filters/GuassianBlur.cs b/src/ImageProcessorCore/Filters/GuassianBlur.cs index a57f43b2c2..b2a0768bc3 100644 --- a/src/ImageProcessorCore/Filters/GuassianBlur.cs +++ b/src/ImageProcessorCore/Filters/GuassianBlur.cs @@ -8,22 +8,22 @@ namespace ImageProcessorCore using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Applies a Guassian blur to the image. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image this method extends. /// The 'sigma' value representing the weight of the blur. /// A delegate which is called as progress is made processing the image. - /// The . - public static Image GuassianBlur(this Image source, float sigma = 3f, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image GuassianBlur(this Image source, float sigma = 3f, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { return GuassianBlur(source, sigma, source.Bounds, progressHandler); } @@ -31,20 +31,20 @@ namespace ImageProcessorCore /// /// Applies a Guassian blur to the image. /// - /// The pixel format. - /// The packed format. long, float. + /// 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. /// /// A delegate which is called as progress is made processing the image. - /// The . - public static Image GuassianBlur(this Image source, float sigma, Rectangle rectangle, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image GuassianBlur(this Image source, float sigma, Rectangle rectangle, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { - GuassianBlurProcessor processor = new GuassianBlurProcessor(sigma); + GuassianBlurProcessor processor = new GuassianBlurProcessor(sigma); processor.OnProgress += progressHandler; try diff --git a/src/ImageProcessorCore/Filters/GuassianSharpen.cs b/src/ImageProcessorCore/Filters/GuassianSharpen.cs index 6fb888cdfc..f3eed80183 100644 --- a/src/ImageProcessorCore/Filters/GuassianSharpen.cs +++ b/src/ImageProcessorCore/Filters/GuassianSharpen.cs @@ -8,22 +8,22 @@ namespace ImageProcessorCore using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Applies a Guassian sharpening filter to the image. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image this method extends. /// The 'sigma' value representing the weight of the blur. /// A delegate which is called as progress is made processing the image. - /// The . - public static Image GuassianSharpen(this Image source, float sigma = 3f, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image GuassianSharpen(this Image source, float sigma = 3f, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { return GuassianSharpen(source, sigma, source.Bounds, progressHandler); } @@ -31,20 +31,20 @@ namespace ImageProcessorCore /// /// Applies a Guassian sharpening filter to the image. /// - /// The pixel format. - /// The packed format. long, float. + /// 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. /// /// A delegate which is called as progress is made processing the image. - /// The . - public static Image GuassianSharpen(this Image source, float sigma, Rectangle rectangle, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image GuassianSharpen(this Image source, float sigma, Rectangle rectangle, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { - GuassianSharpenProcessor processor = new GuassianSharpenProcessor(sigma); + GuassianSharpenProcessor processor = new GuassianSharpenProcessor(sigma); processor.OnProgress += progressHandler; try diff --git a/src/ImageProcessorCore/Filters/Hue.cs b/src/ImageProcessorCore/Filters/Hue.cs index a4de7c6102..d4c86ac3a3 100644 --- a/src/ImageProcessorCore/Filters/Hue.cs +++ b/src/ImageProcessorCore/Filters/Hue.cs @@ -8,22 +8,22 @@ namespace ImageProcessorCore using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Alters the hue component of the image. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image this method extends. /// The angle in degrees to adjust the image. /// A delegate which is called as progress is made processing the image. - /// The . - public static Image Hue(this Image source, float degrees, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image Hue(this Image source, float degrees, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { return Hue(source, degrees, source.Bounds, progressHandler); } @@ -31,20 +31,20 @@ namespace ImageProcessorCore /// /// Alters the hue component of the image. /// - /// The pixel format. - /// The packed format. long, float. + /// 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. /// /// A delegate which is called as progress is made processing the image. - /// The . - public static Image Hue(this Image source, float degrees, Rectangle rectangle, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image Hue(this Image source, float degrees, Rectangle rectangle, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { - HueProcessor processor = new HueProcessor(degrees); + HueProcessor processor = new HueProcessor(degrees); processor.OnProgress += progressHandler; try diff --git a/src/ImageProcessorCore/Filters/Invert.cs b/src/ImageProcessorCore/Filters/Invert.cs index d7888be591..e1f59d8d39 100644 --- a/src/ImageProcessorCore/Filters/Invert.cs +++ b/src/ImageProcessorCore/Filters/Invert.cs @@ -18,9 +18,9 @@ namespace ImageProcessorCore /// The image this method extends. /// A delegate which is called as progress is made processing the image. /// The . - public static Image Invert(this Image source, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + public static Image Invert(this Image source, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { return Invert(source, source.Bounds, progressHandler); } @@ -34,11 +34,11 @@ namespace ImageProcessorCore /// /// A delegate which is called as progress is made processing the image. /// The . - public static Image Invert(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + public static Image Invert(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { - InvertProcessor processor = new InvertProcessor(); + InvertProcessor processor = new InvertProcessor(); processor.OnProgress += progressHandler; try diff --git a/src/ImageProcessorCore/Filters/Kodachrome.cs b/src/ImageProcessorCore/Filters/Kodachrome.cs index 0f4bf2ae83..9a27f2010b 100644 --- a/src/ImageProcessorCore/Filters/Kodachrome.cs +++ b/src/ImageProcessorCore/Filters/Kodachrome.cs @@ -8,21 +8,21 @@ namespace ImageProcessorCore using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Alters the colors of the image recreating an old Kodachrome camera effect. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image this method extends. /// A delegate which is called as progress is made processing the image. - /// The . - public static Image Kodachrome(this Image source, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image Kodachrome(this Image source, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { return Kodachrome(source, source.Bounds, progressHandler); } @@ -30,19 +30,19 @@ namespace ImageProcessorCore /// /// Alters the colors of the image recreating an old Kodachrome camera effect. /// - /// The pixel format. - /// The packed format. long, float. + /// The 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. /// /// A delegate which is called as progress is made processing the image. - /// The . - public static Image Kodachrome(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image Kodachrome(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { - KodachromeProcessor processor = new KodachromeProcessor(); + KodachromeProcessor processor = new KodachromeProcessor(); processor.OnProgress += progressHandler; try diff --git a/src/ImageProcessorCore/Filters/Lomograph.cs b/src/ImageProcessorCore/Filters/Lomograph.cs index 5a484bcc87..fa5f094b45 100644 --- a/src/ImageProcessorCore/Filters/Lomograph.cs +++ b/src/ImageProcessorCore/Filters/Lomograph.cs @@ -8,21 +8,21 @@ namespace ImageProcessorCore using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Alters the colors of the image recreating an old Lomograph camera effect. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image this method extends. /// A delegate which is called as progress is made processing the image. - /// The . - public static Image Lomograph(this Image source, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image Lomograph(this Image source, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { return Lomograph(source, source.Bounds, progressHandler); } @@ -30,19 +30,19 @@ namespace ImageProcessorCore /// /// Alters the colors of the image recreating an old Lomograph camera effect. /// - /// The pixel format. - /// The packed format. long, float. + /// The 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. /// /// A delegate which is called as progress is made processing the image. - /// The . - public static Image Lomograph(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image Lomograph(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { - LomographProcessor processor = new LomographProcessor(); + LomographProcessor processor = new LomographProcessor(); processor.OnProgress += progressHandler; try diff --git a/src/ImageProcessorCore/Filters/Pixelate.cs b/src/ImageProcessorCore/Filters/Pixelate.cs index 8bfb7cd2d5..32b443881e 100644 --- a/src/ImageProcessorCore/Filters/Pixelate.cs +++ b/src/ImageProcessorCore/Filters/Pixelate.cs @@ -9,10 +9,10 @@ namespace ImageProcessorCore using System; /// - /// Extension methods for the type. + /// Extension methods for the type. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. public static partial class ImageExtensions { /// @@ -21,10 +21,10 @@ namespace ImageProcessorCore /// The image this method extends. /// The size of the pixels. /// A delegate which is called as progress is made processing the image. - /// The . - public static Image Pixelate(this Image source, int size = 4, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image Pixelate(this Image source, int size = 4, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { return Pixelate(source, size, source.Bounds, progressHandler); } @@ -38,17 +38,17 @@ namespace ImageProcessorCore /// The structure that specifies the portion of the image object to alter. /// /// A delegate which is called as progress is made processing the image. - /// The . - public static Image Pixelate(this Image source, int size, Rectangle rectangle, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image Pixelate(this Image source, int size, Rectangle rectangle, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { if (size <= 0 || size > source.Height || size > source.Width) { throw new ArgumentOutOfRangeException(nameof(size)); } - PixelateProcessor processor = new PixelateProcessor(size); + PixelateProcessor processor = new PixelateProcessor(size); processor.OnProgress += progressHandler; try diff --git a/src/ImageProcessorCore/Filters/Polaroid.cs b/src/ImageProcessorCore/Filters/Polaroid.cs index e56496322c..99dfb0a780 100644 --- a/src/ImageProcessorCore/Filters/Polaroid.cs +++ b/src/ImageProcessorCore/Filters/Polaroid.cs @@ -8,21 +8,21 @@ namespace ImageProcessorCore using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Alters the colors of the image recreating an old Polaroid camera effect. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image this method extends. /// A delegate which is called as progress is made processing the image. - /// The . - public static Image Polaroid(this Image source, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image Polaroid(this Image source, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { return Polaroid(source, source.Bounds, progressHandler); } @@ -30,19 +30,19 @@ namespace ImageProcessorCore /// /// Alters the colors of the image recreating an old Polaroid camera effect. /// - /// The pixel format. - /// The packed format. long, float. + /// The 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. /// /// A delegate which is called as progress is made processing the image. - /// The . - public static Image Polaroid(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image Polaroid(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { - PolaroidProcessor processor = new PolaroidProcessor(); + PolaroidProcessor processor = new PolaroidProcessor(); processor.OnProgress += progressHandler; try diff --git a/src/ImageProcessorCore/Filters/Processors/AlphaProcessor.cs b/src/ImageProcessorCore/Filters/Processors/AlphaProcessor.cs index 19a3fb518a..2b04b6a337 100644 --- a/src/ImageProcessorCore/Filters/Processors/AlphaProcessor.cs +++ b/src/ImageProcessorCore/Filters/Processors/AlphaProcessor.cs @@ -10,16 +10,16 @@ namespace ImageProcessorCore.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. long, float. - public class AlphaProcessor : ImageProcessor - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class AlphaProcessor : ImageProcessor + where TColor : IPackedVector + where TPacked : struct { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The percentage to adjust the opacity of the image. Must be between 0 and 100. /// @@ -37,7 +37,7 @@ namespace ImageProcessorCore.Processors public int Value { get; } /// - protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) + protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) { float alpha = this.Value / 100F; int startX = sourceRectangle.X; @@ -62,8 +62,8 @@ namespace ImageProcessorCore.Processors Vector4 alphaVector = new Vector4(1, 1, 1, alpha); - using (IPixelAccessor sourcePixels = source.Lock()) - using (IPixelAccessor targetPixels = target.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock()) { Parallel.For( minY, @@ -75,7 +75,7 @@ namespace ImageProcessorCore.Processors for (int x = minX; x < maxX; x++) { int offsetX = x - startX; - T packed = default(T); + TColor packed = default(TColor); packed.PackFromVector4(sourcePixels[offsetX, offsetY].ToVector4() * alphaVector); targetPixels[offsetX, offsetY] = packed; } diff --git a/src/ImageProcessorCore/Filters/Processors/BackgroundColorProcessor.cs b/src/ImageProcessorCore/Filters/Processors/BackgroundColorProcessor.cs index b45cc95abd..b5a22e796e 100644 --- a/src/ImageProcessorCore/Filters/Processors/BackgroundColorProcessor.cs +++ b/src/ImageProcessorCore/Filters/Processors/BackgroundColorProcessor.cs @@ -12,9 +12,9 @@ namespace ImageProcessorCore.Processors /// /// Sets the background color of the image. /// - public class BackgroundColorProcessor : ImageProcessor - where T : IPackedVector - where TP : struct + public class BackgroundColorProcessor : ImageProcessor + where TColor : IPackedVector + where TPacked : struct { /// /// The epsilon for comparing floating point numbers. @@ -22,10 +22,10 @@ namespace ImageProcessorCore.Processors private const float Epsilon = 0.001f; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The to set the background color to. - public BackgroundColorProcessor(T color) + public BackgroundColorProcessor(TColor color) { this.Value = color; } @@ -33,10 +33,10 @@ namespace ImageProcessorCore.Processors /// /// Gets the background color value. /// - public T Value { get; } + public TColor Value { get; } /// - protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) + protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) { int startX = sourceRectangle.X; int endX = sourceRectangle.Right; @@ -60,8 +60,8 @@ namespace ImageProcessorCore.Processors Vector4 backgroundColor = this.Value.ToVector4(); - using (IPixelAccessor sourcePixels = source.Lock()) - using (IPixelAccessor targetPixels = target.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock()) { Parallel.For( minY, @@ -86,7 +86,7 @@ namespace ImageProcessorCore.Processors color = backgroundColor; } - T packed = default(T); + TColor packed = default(TColor); packed.PackFromVector4(color); targetPixels[offsetX, offsetY] = packed; } diff --git a/src/ImageProcessorCore/Filters/Processors/Binarization/BinaryThresholdProcessor.cs b/src/ImageProcessorCore/Filters/Processors/Binarization/BinaryThresholdProcessor.cs index 02b7def4a7..bb6845878d 100644 --- a/src/ImageProcessorCore/Filters/Processors/Binarization/BinaryThresholdProcessor.cs +++ b/src/ImageProcessorCore/Filters/Processors/Binarization/BinaryThresholdProcessor.cs @@ -9,17 +9,17 @@ namespace ImageProcessorCore.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. long, float. - public class BinaryThresholdProcessor : ImageProcessor - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class BinaryThresholdProcessor : ImageProcessor + where TColor : IPackedVector + where TPacked : struct { /// - /// 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. /// @@ -31,11 +31,11 @@ namespace ImageProcessorCore.Processors Guard.MustBeBetweenOrEqualTo(threshold, 0, 1, nameof(threshold)); this.Value = threshold; - T upper = default(T); + TColor upper = default(TColor); upper.PackFromVector4(Color.White.ToVector4()); this.UpperColor = upper; - T lower = default(T); + TColor lower = default(TColor); lower.PackFromVector4(Color.Black.ToVector4()); this.LowerColor = lower; } @@ -48,25 +48,25 @@ namespace ImageProcessorCore.Processors /// /// Gets or sets the color to use for pixels that are above the threshold. /// - public T UpperColor { get; set; } + public TColor UpperColor { get; set; } /// /// Gets or sets the color to use for pixels that fall below the threshold. /// - public T LowerColor { get; set; } + public TColor LowerColor { get; set; } /// - protected override void OnApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) + protected override void OnApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) { - new GrayscaleBt709Processor().Apply(source, source, sourceRectangle); + new GrayscaleBt709Processor().Apply(source, source, sourceRectangle); } /// - protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) + protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) { float threshold = this.Value; - T upper = this.UpperColor; - T lower = this.LowerColor; + TColor upper = this.UpperColor; + TColor lower = this.LowerColor; int startX = sourceRectangle.X; int endX = sourceRectangle.Right; @@ -87,8 +87,8 @@ namespace ImageProcessorCore.Processors startY = 0; } - using (IPixelAccessor sourcePixels = source.Lock()) - using (IPixelAccessor targetPixels = target.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock()) { Parallel.For( minY, @@ -100,7 +100,7 @@ namespace ImageProcessorCore.Processors for (int x = minX; x < maxX; x++) { int offsetX = x - startX; - T color = sourcePixels[offsetX, offsetY]; + TColor color = sourcePixels[offsetX, offsetY]; // Any channel will do since it's Grayscale. targetPixels[offsetX, offsetY] = color.ToVector4().X >= threshold ? upper : lower; @@ -111,4 +111,4 @@ namespace ImageProcessorCore.Processors } } } -} +} \ No newline at end of file diff --git a/src/ImageProcessorCore/Filters/Processors/BlendProcessor.cs b/src/ImageProcessorCore/Filters/Processors/BlendProcessor.cs index 37ad39852e..1cf51c1d1c 100644 --- a/src/ImageProcessorCore/Filters/Processors/BlendProcessor.cs +++ b/src/ImageProcessorCore/Filters/Processors/BlendProcessor.cs @@ -12,26 +12,26 @@ namespace ImageProcessorCore.Processors /// /// Combines two images together by blending the pixels. /// - /// The pixel format. - /// The packed format. long, float. - public class BlendProcessor : ImageProcessor - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class BlendProcessor : ImageProcessor + where TColor : IPackedVector + where TPacked : struct { /// /// The image to blend. /// - private readonly ImageBase blend; + private readonly ImageBase blend; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// The image to blend with the currently processing image. /// Disposal of this image is the responsibility of the developer. /// /// The opacity of the image to blend. Between 0 and 100. - public BlendProcessor(ImageBase image, int alpha = 100) + public BlendProcessor(ImageBase image, int alpha = 100) { Guard.MustBeBetweenOrEqualTo(alpha, 0, 100, nameof(alpha)); this.blend = image; @@ -44,7 +44,7 @@ namespace ImageProcessorCore.Processors public int Value { get; } /// - protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) + protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) { int startX = sourceRectangle.X; int endX = sourceRectangle.Right; @@ -69,9 +69,9 @@ namespace ImageProcessorCore.Processors float alpha = this.Value / 100F; - using (IPixelAccessor toBlendPixels = this.blend.Lock()) - using (IPixelAccessor sourcePixels = source.Lock()) - using (IPixelAccessor targetPixels = target.Lock()) + using (PixelAccessor toBlendPixels = this.blend.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock()) { Parallel.For( minY, @@ -96,7 +96,7 @@ namespace ImageProcessorCore.Processors } } - T packed = default(T); + TColor packed = default(TColor); packed.PackFromVector4(color); targetPixels[offsetX, offsetY] = packed; } diff --git a/src/ImageProcessorCore/Filters/Processors/BrightnessProcessor.cs b/src/ImageProcessorCore/Filters/Processors/BrightnessProcessor.cs index 0be59d92c0..f1259dac56 100644 --- a/src/ImageProcessorCore/Filters/Processors/BrightnessProcessor.cs +++ b/src/ImageProcessorCore/Filters/Processors/BrightnessProcessor.cs @@ -10,16 +10,16 @@ namespace ImageProcessorCore.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. long, float. - public class BrightnessProcessor : ImageProcessor - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class BrightnessProcessor : ImageProcessor + where TColor : IPackedVector + where TPacked : struct { /// - /// 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 +37,7 @@ namespace ImageProcessorCore.Processors public int Value { get; } /// - protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) + protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) { float brightness = this.Value / 100F; int startX = sourceRectangle.X; @@ -60,8 +60,8 @@ namespace ImageProcessorCore.Processors startY = 0; } - using (IPixelAccessor sourcePixels = source.Lock()) - using (IPixelAccessor targetPixels = target.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock()) { Parallel.For( minY, @@ -79,7 +79,7 @@ namespace ImageProcessorCore.Processors Vector3 transformed = new Vector3(vector.X, vector.Y, vector.Z) + new Vector3(brightness); vector = new Vector4(transformed, vector.W); - T packed = default(T); + TColor packed = default(TColor); packed.PackFromVector4(vector.Compress()); targetPixels[offsetX, offsetY] = packed; diff --git a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/BlackWhiteProcessor.cs b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/BlackWhiteProcessor.cs index 6893d2a8a0..2c7dc644a4 100644 --- a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/BlackWhiteProcessor.cs +++ b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/BlackWhiteProcessor.cs @@ -10,11 +10,11 @@ namespace ImageProcessorCore.Processors /// /// Converts the colors of the image to their black and white equivalent. /// - /// The pixel format. - /// The packed format. long, float. - public class BlackWhiteProcessor : ColorMatrixFilter - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class BlackWhiteProcessor : ColorMatrixFilter + where TColor : IPackedVector + where TPacked : struct { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/AchromatomalyProcessor.cs b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/AchromatomalyProcessor.cs index e8dd077ebc..310be48945 100644 --- a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/AchromatomalyProcessor.cs +++ b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/AchromatomalyProcessor.cs @@ -10,11 +10,11 @@ namespace ImageProcessorCore.Processors /// /// Converts the colors of the image recreating Achromatomaly (Color desensitivity) color blindness. /// - /// The pixel format. - /// The packed format. long, float. - public class AchromatomalyProcessor : ColorMatrixFilter - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class AchromatomalyProcessor : ColorMatrixFilter + where TColor : IPackedVector + where TPacked : struct { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/AchromatopsiaProcessor.cs b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/AchromatopsiaProcessor.cs index 0e7f69a131..3317d79bbd 100644 --- a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/AchromatopsiaProcessor.cs +++ b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/AchromatopsiaProcessor.cs @@ -10,11 +10,11 @@ namespace ImageProcessorCore.Processors /// /// Converts the colors of the image recreating Achromatopsia (Monochrome) color blindness. /// - /// The pixel format. - /// The packed format. long, float. - public class AchromatopsiaProcessor : ColorMatrixFilter - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class AchromatopsiaProcessor : ColorMatrixFilter + where TColor : IPackedVector + where TPacked : struct { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/DeuteranomalyProcessor.cs b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/DeuteranomalyProcessor.cs index b7f48ea1dc..b38f1338ec 100644 --- a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/DeuteranomalyProcessor.cs +++ b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/DeuteranomalyProcessor.cs @@ -10,11 +10,11 @@ namespace ImageProcessorCore.Processors /// /// Converts the colors of the image recreating Deuteranomaly (Green-Weak) color blindness. /// - /// The pixel format. - /// The packed format. long, float. - public class DeuteranomalyProcessor : ColorMatrixFilter - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class DeuteranomalyProcessor : ColorMatrixFilter + where TColor : IPackedVector + where TPacked : struct { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/DeuteranopiaProcessor.cs b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/DeuteranopiaProcessor.cs index 82f50d07fb..593fb20928 100644 --- a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/DeuteranopiaProcessor.cs +++ b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/DeuteranopiaProcessor.cs @@ -10,11 +10,11 @@ namespace ImageProcessorCore.Processors /// /// Converts the colors of the image recreating Deuteranopia (Green-Blind) color blindness. /// - /// The pixel format. - /// The packed format. long, float. - public class DeuteranopiaProcessor : ColorMatrixFilter - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class DeuteranopiaProcessor : ColorMatrixFilter + where TColor : IPackedVector + where TPacked : struct { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/ProtanomalyProcessor.cs b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/ProtanomalyProcessor.cs index 32380cba13..c5be10d3b7 100644 --- a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/ProtanomalyProcessor.cs +++ b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/ProtanomalyProcessor.cs @@ -10,11 +10,11 @@ namespace ImageProcessorCore.Processors /// /// Converts the colors of the image recreating Protanopia (Red-Weak) color blindness. /// - /// The pixel format. - /// The packed format. long, float. - public class ProtanomalyProcessor : ColorMatrixFilter - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class ProtanomalyProcessor : ColorMatrixFilter + where TColor : IPackedVector + where TPacked : struct { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/ProtanopiaProcessor.cs b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/ProtanopiaProcessor.cs index 891b6e06ad..6cb829bd5d 100644 --- a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/ProtanopiaProcessor.cs +++ b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/ProtanopiaProcessor.cs @@ -10,11 +10,11 @@ namespace ImageProcessorCore.Processors /// /// Converts the colors of the image recreating Protanopia (Red-Blind) color blindness. /// - /// The pixel format. - /// The packed format. long, float. - public class ProtanopiaProcessor : ColorMatrixFilter - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class ProtanopiaProcessor : ColorMatrixFilter + where TColor : IPackedVector + where TPacked : struct { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/TritanomalyProcessor.cs b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/TritanomalyProcessor.cs index 88e5fd5dcb..85eed5f80f 100644 --- a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/TritanomalyProcessor.cs +++ b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/TritanomalyProcessor.cs @@ -10,11 +10,11 @@ namespace ImageProcessorCore.Processors /// /// Converts the colors of the image recreating Tritanomaly (Blue-Weak) color blindness. /// - /// The pixel format. - /// The packed format. long, float. - public class TritanomalyProcessor : ColorMatrixFilter - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class TritanomalyProcessor : ColorMatrixFilter + where TColor : IPackedVector + where TPacked : struct { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/TritanopiaProcessor.cs b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/TritanopiaProcessor.cs index b708927a24..ada7ecde22 100644 --- a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/TritanopiaProcessor.cs +++ b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorBlindness/TritanopiaProcessor.cs @@ -10,11 +10,11 @@ namespace ImageProcessorCore.Processors /// /// Converts the colors of the image recreating Tritanopia (Blue-Blind) color blindness. /// - /// The pixel format. - /// The packed format. long, float. - public class TritanopiaProcessor : ColorMatrixFilter - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class TritanopiaProcessor : ColorMatrixFilter + where TColor : IPackedVector + where TPacked : struct { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorMatrixFilter.cs b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorMatrixFilter.cs index cbe1d0a3f6..b9817b656e 100644 --- a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorMatrixFilter.cs +++ b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/ColorMatrixFilter.cs @@ -12,11 +12,11 @@ namespace ImageProcessorCore.Processors /// /// The color matrix filter. Inherit from this class to perform operation involving color matrices. /// - /// The pixel format. - /// The packed format. long, float. - public abstract class ColorMatrixFilter : ImageProcessor, IColorMatrixFilter - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public abstract class ColorMatrixFilter : ImageProcessor, IColorMatrixFilter + where TColor : IPackedVector + where TPacked : struct { /// public abstract Matrix4x4 Matrix { get; } @@ -25,7 +25,7 @@ namespace ImageProcessorCore.Processors public override bool Compand { get; set; } = true; /// - protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) + protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) { int startX = sourceRectangle.X; int endX = sourceRectangle.Right; @@ -50,8 +50,8 @@ namespace ImageProcessorCore.Processors Matrix4x4 matrix = this.Matrix; bool compand = this.Compand; - using (IPixelAccessor sourcePixels = source.Lock()) - using (IPixelAccessor targetPixels = target.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock()) { Parallel.For( minY, @@ -80,7 +80,7 @@ namespace ImageProcessorCore.Processors /// /// The . /// - private T ApplyMatrix(T color, Matrix4x4 matrix, bool compand) + private TColor ApplyMatrix(TColor color, Matrix4x4 matrix, bool compand) { Vector4 vector = color.ToVector4(); @@ -91,7 +91,7 @@ namespace ImageProcessorCore.Processors Vector3 transformed = Vector3.Transform(new Vector3(vector.X, vector.Y, vector.Z), matrix); vector = new Vector4(transformed, vector.W); - T packed = default(T); + TColor packed = default(TColor); packed.PackFromVector4(compand ? vector.Compress() : vector); return packed; } diff --git a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/GrayscaleBt601Processor.cs b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/GrayscaleBt601Processor.cs index b650f0cfc0..ff48a2e022 100644 --- a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/GrayscaleBt601Processor.cs +++ b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/GrayscaleBt601Processor.cs @@ -11,11 +11,11 @@ namespace ImageProcessorCore.Processors /// Converts the colors of the image to Grayscale applying the formula as specified by /// ITU-R Recommendation BT.601 . /// - /// The pixel format. - /// The packed format. long, float. - public class GrayscaleBt601Processor : ColorMatrixFilter - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class GrayscaleBt601Processor : ColorMatrixFilter + where TColor : IPackedVector + where TPacked : struct { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/GrayscaleBt709Processor.cs b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/GrayscaleBt709Processor.cs index 435f00d198..6da2baee39 100644 --- a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/GrayscaleBt709Processor.cs +++ b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/GrayscaleBt709Processor.cs @@ -11,9 +11,9 @@ namespace ImageProcessorCore.Processors /// Converts the colors of the image to Grayscale applying the formula as specified by /// ITU-R Recommendation BT.709 . /// - public class GrayscaleBt709Processor : ColorMatrixFilter - where T : IPackedVector - where TP : struct + public class GrayscaleBt709Processor : ColorMatrixFilter + where TColor : IPackedVector + where TPacked : struct { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/HueProcessor.cs b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/HueProcessor.cs index ab68741696..a497f5bd43 100644 --- a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/HueProcessor.cs +++ b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/HueProcessor.cs @@ -9,13 +9,13 @@ namespace ImageProcessorCore.Processors using System.Numerics; /// - /// An to change the hue of an . + /// An to change the hue of an . /// - /// The pixel format. - /// The packed format. long, float. - public class HueProcessor : ColorMatrixFilter - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class HueProcessor : ColorMatrixFilter + where TColor : IPackedVector + where TPacked : struct { /// /// The used to alter the image. diff --git a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/IColorMatrixFilter.cs b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/IColorMatrixFilter.cs index a3fc7d65c5..cb4c3c36a6 100644 --- a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/IColorMatrixFilter.cs +++ b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/IColorMatrixFilter.cs @@ -11,9 +11,9 @@ namespace ImageProcessorCore.Processors /// Encapsulates properties and methods for creating processors that utilize a matrix to /// alter the image pixels. /// - public interface IColorMatrixFilter : IImageProcessor - where T : IPackedVector - where TP : struct + public interface IColorMatrixFilter : IImageProcessor + where TColor : IPackedVector + where TPacked : struct { /// /// Gets the used to alter the image. diff --git a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/KodachromeProcessor.cs b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/KodachromeProcessor.cs index f7a84fc082..5655cfe255 100644 --- a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/KodachromeProcessor.cs +++ b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/KodachromeProcessor.cs @@ -10,11 +10,11 @@ namespace ImageProcessorCore.Processors /// /// Converts the colors of the image recreating an old Kodachrome camera effect. /// - /// The pixel format. - /// The packed format. long, float. - public class KodachromeProcessor : ColorMatrixFilter - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class KodachromeProcessor : ColorMatrixFilter + where TColor : IPackedVector + where TPacked : struct { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/LomographProcessor.cs b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/LomographProcessor.cs index 7346e7b80a..10de7109cd 100644 --- a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/LomographProcessor.cs +++ b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/LomographProcessor.cs @@ -10,11 +10,11 @@ namespace ImageProcessorCore.Processors /// /// Converts the colors of the image recreating an old Lomograph effect. /// - /// The pixel format. - /// The packed format. long, float. - public class LomographProcessor : ColorMatrixFilter - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class LomographProcessor : ColorMatrixFilter + where TColor : IPackedVector + where TPacked : struct { /// public override Matrix4x4 Matrix => new Matrix4x4() @@ -28,11 +28,11 @@ namespace ImageProcessorCore.Processors }; /// - protected override void AfterApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) + protected override void AfterApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) { - T packed = default(T); + TColor packed = default(TColor); packed.PackFromBytes(0, 10, 0, 255); // Very dark (mostly black) lime green. - new VignetteProcessor { VignetteColor = packed }.Apply(target, target, sourceRectangle); + new VignetteProcessor { VignetteColor = packed }.Apply(target, target, sourceRectangle); } } } diff --git a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/PolaroidProcessor.cs b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/PolaroidProcessor.cs index ebcf722b28..956896c649 100644 --- a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/PolaroidProcessor.cs +++ b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/PolaroidProcessor.cs @@ -10,11 +10,11 @@ namespace ImageProcessorCore.Processors /// /// Converts the colors of the image recreating an old Polaroid effect. /// - /// The pixel format. - /// The packed format. long, float. - public class PolaroidProcessor : ColorMatrixFilter - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class PolaroidProcessor : ColorMatrixFilter + where TColor : IPackedVector + where TPacked : struct { /// public override Matrix4x4 Matrix => new Matrix4x4() @@ -34,15 +34,15 @@ namespace ImageProcessorCore.Processors }; /// - protected override void AfterApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) + protected override void AfterApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) { - T packedV = default(T); + TColor packedV = default(TColor); packedV.PackFromBytes(102, 34, 0, 255); // Very dark orange [Brown tone] - new VignetteProcessor { VignetteColor = packedV }.Apply(target, target, sourceRectangle); + new VignetteProcessor { VignetteColor = packedV }.Apply(target, target, sourceRectangle); - T packedG = default(T); + TColor packedG = default(TColor); packedG.PackFromBytes(255, 153, 102, 178); // Light orange - new GlowProcessor { GlowColor = packedG, Radius = target.Width / 4F }.Apply(target, target, sourceRectangle); + new GlowProcessor { GlowColor = packedG, Radius = target.Width / 4F }.Apply(target, target, sourceRectangle); } } } diff --git a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/SaturationProcessor.cs b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/SaturationProcessor.cs index 1afd3db5ff..ae031fed9e 100644 --- a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/SaturationProcessor.cs +++ b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/SaturationProcessor.cs @@ -8,13 +8,13 @@ namespace ImageProcessorCore.Processors using System.Numerics; /// - /// An to change the saturation of an . + /// An to change the saturation of an . /// - /// The pixel format. - /// The packed format. long, float. - public class SaturationProcessor : ColorMatrixFilter - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class SaturationProcessor : ColorMatrixFilter + where TColor : IPackedVector + where TPacked : struct { /// /// The saturation to be applied to the image. diff --git a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/SepiaProcessor.cs b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/SepiaProcessor.cs index 60ba27c0e6..6a4b2c8802 100644 --- a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/SepiaProcessor.cs +++ b/src/ImageProcessorCore/Filters/Processors/ColorMatrix/SepiaProcessor.cs @@ -11,11 +11,11 @@ namespace ImageProcessorCore.Processors /// Converts the colors of the image to their sepia equivalent. /// The formula used matches the svg specification. /// - /// The pixel format. - /// The packed format. long, float. - public class SepiaProcessor : ColorMatrixFilter - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class SepiaProcessor : ColorMatrixFilter + where TColor : IPackedVector + where TPacked : struct { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageProcessorCore/Filters/Processors/ContrastProcessor.cs b/src/ImageProcessorCore/Filters/Processors/ContrastProcessor.cs index 0c5d7e2258..91a7e4a124 100644 --- a/src/ImageProcessorCore/Filters/Processors/ContrastProcessor.cs +++ b/src/ImageProcessorCore/Filters/Processors/ContrastProcessor.cs @@ -10,13 +10,13 @@ namespace ImageProcessorCore.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 : ImageProcessor - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class ContrastProcessor : ImageProcessor + where TColor : IPackedVector + where TPacked : struct { /// /// Initializes a new instance of the class. @@ -37,7 +37,7 @@ namespace ImageProcessorCore.Processors public int Value { get; } /// - protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) + protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) { float contrast = (100F + this.Value) / 100F; int startX = sourceRectangle.X; @@ -62,8 +62,8 @@ namespace ImageProcessorCore.Processors startY = 0; } - using (IPixelAccessor sourcePixels = source.Lock()) - using (IPixelAccessor targetPixels = target.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock()) { Parallel.For( minY, @@ -80,7 +80,7 @@ namespace ImageProcessorCore.Processors vector -= shiftVector; vector *= contrastVector; vector += shiftVector; - T packed = default(T); + TColor packed = default(TColor); packed.PackFromVector4(vector.Compress()); targetPixels[offsetX, offsetY] = packed; } diff --git a/src/ImageProcessorCore/Filters/Processors/Convolution/BoxBlurProcessor.cs b/src/ImageProcessorCore/Filters/Processors/Convolution/BoxBlurProcessor.cs index a4fe4da0f1..f8c2d9109a 100644 --- a/src/ImageProcessorCore/Filters/Processors/Convolution/BoxBlurProcessor.cs +++ b/src/ImageProcessorCore/Filters/Processors/Convolution/BoxBlurProcessor.cs @@ -8,11 +8,11 @@ namespace ImageProcessorCore.Processors /// /// Applies a Box blur filter to the image. /// - /// The pixel format. - /// The packed format. long, float. - public class BoxBlurProcessor : Convolution2PassFilter - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class BoxBlurProcessor : Convolution2PassFilter + where TColor : IPackedVector + where TPacked : struct { /// /// The maximum size of the kernal in either direction. @@ -47,7 +47,7 @@ namespace ImageProcessorCore.Processors public override float[,] KernelY => this.kernelY; /// - protected override void OnApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) + protected override void OnApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) { if (this.kernelY == null) { diff --git a/src/ImageProcessorCore/Filters/Processors/Convolution/Convolution2DFilter.cs b/src/ImageProcessorCore/Filters/Processors/Convolution/Convolution2DFilter.cs index d586c3cd5a..264406b881 100644 --- a/src/ImageProcessorCore/Filters/Processors/Convolution/Convolution2DFilter.cs +++ b/src/ImageProcessorCore/Filters/Processors/Convolution/Convolution2DFilter.cs @@ -12,11 +12,11 @@ namespace ImageProcessorCore.Processors /// /// Defines a filter that uses two one-dimensional matrices to perform convolution against an image. /// - /// The pixel format. - /// The packed format. long, float. - public abstract class Convolution2DFilter : ImageProcessor - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public abstract class Convolution2DFilter : ImageProcessor + where TColor : IPackedVector + where TPacked : struct { /// /// Gets the horizontal gradient operator. @@ -29,7 +29,7 @@ namespace ImageProcessorCore.Processors public abstract float[,] KernelY { get; } /// - protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) + protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) { float[,] kernelX = this.KernelX; float[,] kernelY = this.KernelY; @@ -47,8 +47,8 @@ namespace ImageProcessorCore.Processors int maxY = sourceBottom - 1; int maxX = endX - 1; - using (IPixelAccessor sourcePixels = source.Lock()) - using (IPixelAccessor targetPixels = target.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock()) { Parallel.For( startY, @@ -108,7 +108,7 @@ namespace ImageProcessorCore.Processors float blue = (float)Math.Sqrt((bX * bX) + (bY * bY)); Vector4 targetColor = targetPixels[x, y].ToVector4(); - T packed = default(T); + TColor packed = default(TColor); packed.PackFromVector4(new Vector4(red, green, blue, targetColor.Z)); targetPixels[x, y] = packed; } diff --git a/src/ImageProcessorCore/Filters/Processors/Convolution/Convolution2PassFilter.cs b/src/ImageProcessorCore/Filters/Processors/Convolution/Convolution2PassFilter.cs index b21e005152..74a600d222 100644 --- a/src/ImageProcessorCore/Filters/Processors/Convolution/Convolution2PassFilter.cs +++ b/src/ImageProcessorCore/Filters/Processors/Convolution/Convolution2PassFilter.cs @@ -11,11 +11,11 @@ namespace ImageProcessorCore.Processors /// /// Defines a filter that uses two one-dimensional matrices to perform two-pass convolution against an image. /// - /// The pixel format. - /// The packed format. long, float. - public abstract class Convolution2PassFilter : ImageProcessor - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public abstract class Convolution2PassFilter : ImageProcessor + where TColor : IPackedVector + where TPacked : struct { /// /// Gets the horizontal gradient operator. @@ -28,18 +28,18 @@ namespace ImageProcessorCore.Processors public abstract float[,] KernelY { get; } /// - protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) + protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) { float[,] kernelX = this.KernelX; float[,] kernelY = this.KernelY; - ImageBase firstPass = new Image(source.Width, source.Height); + ImageBase firstPass = new Image(source.Width, source.Height); this.ApplyConvolution(firstPass, source, sourceRectangle, startY, endY, kernelX); this.ApplyConvolution(target, firstPass, sourceRectangle, startY, endY, kernelY); } /// - /// 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. /// /// Target image to apply the process to. @@ -50,7 +50,7 @@ namespace ImageProcessorCore.Processors /// The index of the row within the source image to start processing. /// The index of the row within the source image to end processing. /// The kernel operator. - private void ApplyConvolution(ImageBase target, ImageBase source, Rectangle sourceRectangle, int startY, int endY, float[,] kernel) + private void ApplyConvolution(ImageBase target, ImageBase source, Rectangle sourceRectangle, int startY, int endY, float[,] kernel) { int kernelHeight = kernel.GetLength(0); int kernelWidth = kernel.GetLength(1); @@ -63,8 +63,8 @@ namespace ImageProcessorCore.Processors int maxY = sourceBottom - 1; int maxX = endX - 1; - using (IPixelAccessor sourcePixels = source.Lock()) - using (IPixelAccessor targetPixels = target.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock()) { Parallel.For( startY, @@ -96,7 +96,7 @@ namespace ImageProcessorCore.Processors } } - T packed = default(T); + TColor packed = default(TColor); packed.PackFromVector4(destination); targetPixels[x, y] = packed; } diff --git a/src/ImageProcessorCore/Filters/Processors/Convolution/ConvolutionFilter.cs b/src/ImageProcessorCore/Filters/Processors/Convolution/ConvolutionFilter.cs index 9fd1e19ee8..dfc026bae4 100644 --- a/src/ImageProcessorCore/Filters/Processors/Convolution/ConvolutionFilter.cs +++ b/src/ImageProcessorCore/Filters/Processors/Convolution/ConvolutionFilter.cs @@ -11,9 +11,9 @@ namespace ImageProcessorCore.Processors /// /// Defines a filter that uses a 2 dimensional matrix to perform convolution against an image. /// - public abstract class ConvolutionFilter : ImageProcessor - where T : IPackedVector - where TP : struct + public abstract class ConvolutionFilter : ImageProcessor + where TColor : IPackedVector + where TPacked : struct { /// /// Gets the 2d gradient operator. @@ -21,7 +21,7 @@ namespace ImageProcessorCore.Processors public abstract float[,] KernelXY { get; } /// - protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) + protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) { float[,] kernelX = this.KernelXY; int kernelLength = kernelX.GetLength(0); @@ -34,8 +34,8 @@ namespace ImageProcessorCore.Processors int maxY = sourceBottom - 1; int maxX = endX - 1; - using (IPixelAccessor sourcePixels = source.Lock()) - using (IPixelAccessor targetPixels = target.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock()) { Parallel.For( startY, @@ -82,7 +82,7 @@ namespace ImageProcessorCore.Processors float blue = bX; Vector4 targetColor = targetPixels[x, y].ToVector4(); - T packed = default(T); + TColor packed = default(TColor); packed.PackFromVector4(new Vector4(red, green, blue, targetColor.Z)); targetPixels[x, y] = packed; diff --git a/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/EdgeDetector2DFilter.cs b/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/EdgeDetector2DFilter.cs index 4effae8b0e..6475ad7cba 100644 --- a/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/EdgeDetector2DFilter.cs +++ b/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/EdgeDetector2DFilter.cs @@ -9,19 +9,19 @@ namespace ImageProcessorCore.Processors /// Defines a filter that detects edges within an image using two /// one-dimensional matrices. /// - public abstract class EdgeDetector2DFilter : Convolution2DFilter, IEdgeDetectorFilter - where T : IPackedVector - where TP : struct + public abstract class EdgeDetector2DFilter : Convolution2DFilter, IEdgeDetectorFilter + where TColor : IPackedVector + where TPacked : struct { /// public bool Grayscale { get; set; } /// - protected override void OnApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) + protected override void OnApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) { if (this.Grayscale) { - new GrayscaleBt709Processor().Apply(source, source, sourceRectangle); + new GrayscaleBt709Processor().Apply(source, source, sourceRectangle); } } } diff --git a/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/EdgeDetectorFilter.cs b/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/EdgeDetectorFilter.cs index a82f0d4caf..2d221664da 100644 --- a/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/EdgeDetectorFilter.cs +++ b/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/EdgeDetectorFilter.cs @@ -9,19 +9,19 @@ namespace ImageProcessorCore.Processors /// Defines a filter that detects edges within an image using a single /// two dimensional matrix. /// - public abstract class EdgeDetectorFilter : ConvolutionFilter, IEdgeDetectorFilter - where T : IPackedVector - where TP : struct + public abstract class EdgeDetectorFilter : ConvolutionFilter, IEdgeDetectorFilter + where TColor : IPackedVector + where TPacked : struct { /// public bool Grayscale { get; set; } /// - protected override void OnApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) + protected override void OnApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) { if (this.Grayscale) { - new GrayscaleBt709Processor().Apply(source, source, sourceRectangle); + new GrayscaleBt709Processor().Apply(source, source, sourceRectangle); } } } diff --git a/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/IEdgeDetectorFilter.cs b/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/IEdgeDetectorFilter.cs index 9d9485875b..e101612b60 100644 --- a/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/IEdgeDetectorFilter.cs +++ b/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/IEdgeDetectorFilter.cs @@ -8,9 +8,9 @@ namespace ImageProcessorCore.Processors /// /// Provides properties and methods allowing the detection of edges within an image. /// - public interface IEdgeDetectorFilter : IImageProcessor, IEdgeDetectorFilter - where T : IPackedVector - where TP : struct + public interface IEdgeDetectorFilter : IImageProcessor, IEdgeDetectorFilter + where TColor : IPackedVector + where TPacked : struct { } diff --git a/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs b/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs index 59327467ee..a7d31a6078 100644 --- a/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs +++ b/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs @@ -9,11 +9,11 @@ namespace ImageProcessorCore.Processors /// The Kayyali operator filter. /// /// - /// The pixel format. - /// The packed format. long, float. - public class KayyaliProcessor : EdgeDetector2DFilter - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class KayyaliProcessor : EdgeDetector2DFilter + where TColor : IPackedVector + where TPacked : struct { /// public override float[,] KernelX => new float[,] diff --git a/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/KirschProcessor.cs b/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/KirschProcessor.cs index aba7e26d25..0c06106e34 100644 --- a/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/KirschProcessor.cs +++ b/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/KirschProcessor.cs @@ -9,11 +9,11 @@ namespace ImageProcessorCore.Processors /// The Kirsch operator filter. /// /// - /// The pixel format. - /// The packed format. long, float. - public class KirschProcessor : EdgeDetector2DFilter - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class KirschProcessor : EdgeDetector2DFilter + where TColor : IPackedVector + where TPacked : struct { /// public override float[,] KernelX => new float[,] diff --git a/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs b/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs index 31829a4220..47eb02202b 100644 --- a/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs +++ b/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs @@ -9,11 +9,11 @@ namespace ImageProcessorCore.Processors /// The Laplacian 3 x 3 operator filter. /// /// - /// The pixel format. - /// The packed format. long, float. - public class Laplacian3X3Processor : EdgeDetectorFilter - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class Laplacian3X3Processor : EdgeDetectorFilter + where TColor : IPackedVector + where TPacked : struct { /// public override float[,] KernelXY => new float[,] diff --git a/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs b/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs index d43876b56f..14a66348cc 100644 --- a/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs +++ b/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs @@ -9,11 +9,11 @@ namespace ImageProcessorCore.Processors /// The Laplacian 5 x 5 operator filter. /// /// - /// The pixel format. - /// The packed format. long, float. - public class Laplacian5X5Processor : EdgeDetectorFilter - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class Laplacian5X5Processor : EdgeDetectorFilter + where TColor : IPackedVector + where TPacked : struct { /// public override float[,] KernelXY => new float[,] diff --git a/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs b/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs index e470136100..1899a68a04 100644 --- a/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs +++ b/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs @@ -9,11 +9,11 @@ namespace ImageProcessorCore.Processors /// The Laplacian of Gaussian operator filter. /// /// - /// The pixel format. - /// The packed format. long, float. - public class LaplacianOfGaussianProcessor : EdgeDetectorFilter - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class LaplacianOfGaussianProcessor : EdgeDetectorFilter + where TColor : IPackedVector + where TPacked : struct { /// public override float[,] KernelXY => new float[,] diff --git a/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/PrewittProcessor.cs b/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/PrewittProcessor.cs index 4ce4c7675c..068660588a 100644 --- a/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/PrewittProcessor.cs +++ b/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/PrewittProcessor.cs @@ -9,11 +9,11 @@ namespace ImageProcessorCore.Processors /// The Prewitt operator filter. /// /// - /// The pixel format. - /// The packed format. long, float. - public class PrewittProcessor : EdgeDetector2DFilter - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class PrewittProcessor : EdgeDetector2DFilter + where TColor : IPackedVector + where TPacked : struct { /// public override float[,] KernelX => new float[,] diff --git a/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs b/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs index b933280c60..69c5abe347 100644 --- a/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs +++ b/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs @@ -9,11 +9,11 @@ namespace ImageProcessorCore.Processors /// The Roberts Cross operator filter. /// /// - /// The pixel format. - /// The packed format. long, float. - public class RobertsCrossProcessor : EdgeDetector2DFilter - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class RobertsCrossProcessor : EdgeDetector2DFilter + where TColor : IPackedVector + where TPacked : struct { /// public override float[,] KernelX => new float[,] diff --git a/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/ScharrProcessor.cs b/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/ScharrProcessor.cs index 1dd4408a01..108e455798 100644 --- a/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/ScharrProcessor.cs +++ b/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/ScharrProcessor.cs @@ -9,11 +9,11 @@ namespace ImageProcessorCore.Processors /// The Scharr operator filter. /// /// - /// The pixel format. - /// The packed format. long, float. - public class ScharrProcessor : EdgeDetector2DFilter - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class ScharrProcessor : EdgeDetector2DFilter + where TColor : IPackedVector + where TPacked : struct { /// public override float[,] KernelX => new float[,] diff --git a/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/SobelProcessor.cs b/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/SobelProcessor.cs index 9459e2ed8d..34b5930159 100644 --- a/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/SobelProcessor.cs +++ b/src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/SobelProcessor.cs @@ -9,11 +9,11 @@ namespace ImageProcessorCore.Processors /// The Sobel operator filter. /// /// - /// The pixel format. - /// The packed format. long, float. - public class SobelProcessor : EdgeDetector2DFilter - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class SobelProcessor : EdgeDetector2DFilter + where TColor : IPackedVector + where TPacked : struct { /// public override float[,] KernelX => new float[,] diff --git a/src/ImageProcessorCore/Filters/Processors/Convolution/GuassianBlurProcessor.cs b/src/ImageProcessorCore/Filters/Processors/Convolution/GuassianBlurProcessor.cs index 23d6d94378..7ab5fe4fbd 100644 --- a/src/ImageProcessorCore/Filters/Processors/Convolution/GuassianBlurProcessor.cs +++ b/src/ImageProcessorCore/Filters/Processors/Convolution/GuassianBlurProcessor.cs @@ -10,11 +10,11 @@ namespace ImageProcessorCore.Processors /// /// Applies a Gaussian blur filter to the image. /// - /// The pixel format. - /// The packed format. long, float. - public class GuassianBlurProcessor : Convolution2PassFilter - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class GuassianBlurProcessor : Convolution2PassFilter + where TColor : IPackedVector + where TPacked : struct { /// /// The maximum size of the kernal in either direction. @@ -81,7 +81,7 @@ namespace ImageProcessorCore.Processors public override float[,] KernelY => this.kernelY; /// - protected override void OnApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) + protected override void OnApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) { if (this.kernelY == null) { diff --git a/src/ImageProcessorCore/Filters/Processors/Convolution/GuassianSharpenProcessor.cs b/src/ImageProcessorCore/Filters/Processors/Convolution/GuassianSharpenProcessor.cs index edfe594513..2c290f2dfa 100644 --- a/src/ImageProcessorCore/Filters/Processors/Convolution/GuassianSharpenProcessor.cs +++ b/src/ImageProcessorCore/Filters/Processors/Convolution/GuassianSharpenProcessor.cs @@ -10,11 +10,11 @@ namespace ImageProcessorCore.Processors /// /// Applies a Gaussian sharpening filter to the image. /// - /// The pixel format. - /// The packed format. long, float. - public class GuassianSharpenProcessor : Convolution2PassFilter - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class GuassianSharpenProcessor : Convolution2PassFilter + where TColor : IPackedVector + where TPacked : struct { /// /// The maximum size of the kernal in either direction. @@ -83,7 +83,7 @@ namespace ImageProcessorCore.Processors public override float[,] KernelY => this.kernelY; /// - protected override void OnApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) + protected override void OnApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) { if (this.kernelY == null) { diff --git a/src/ImageProcessorCore/Filters/Processors/GlowProcessor.cs b/src/ImageProcessorCore/Filters/Processors/GlowProcessor.cs index e854f798cf..ee6b07d17d 100644 --- a/src/ImageProcessorCore/Filters/Processors/GlowProcessor.cs +++ b/src/ImageProcessorCore/Filters/Processors/GlowProcessor.cs @@ -10,20 +10,20 @@ namespace ImageProcessorCore.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. long, float. - public class GlowProcessor : ImageProcessor - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class GlowProcessor : ImageProcessor + where TColor : IPackedVector + where TPacked : struct { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// public GlowProcessor() { - T color = default(T); + TColor color = default(TColor); color.PackFromVector4(Color.Black.ToVector4()); this.GlowColor = color; } @@ -31,7 +31,7 @@ namespace ImageProcessorCore.Processors /// /// Gets or sets the glow color to apply. /// - public T GlowColor { get; set; } + public TColor GlowColor { get; set; } /// /// Gets or sets the the radius. @@ -39,11 +39,11 @@ namespace ImageProcessorCore.Processors public float Radius { get; set; } /// - protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) + protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) { int startX = sourceRectangle.X; int endX = sourceRectangle.Right; - T glowColor = this.GlowColor; + TColor glowColor = this.GlowColor; Vector2 centre = Rectangle.Center(sourceRectangle).ToVector2(); float maxDistance = this.Radius > 0 ? Math.Min(this.Radius, sourceRectangle.Width * .5F) : sourceRectangle.Width * .5F; Ellipse ellipse = new Ellipse(new Point(centre), maxDistance, maxDistance); @@ -65,8 +65,8 @@ namespace ImageProcessorCore.Processors startY = 0; } - using (IPixelAccessor sourcePixels = source.Lock()) - using (IPixelAccessor targetPixels = target.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock()) { Parallel.For( minY, @@ -83,7 +83,7 @@ namespace ImageProcessorCore.Processors // TODO: Premultiply? float distance = Vector2.Distance(centre, new Vector2(offsetX, offsetY)); Vector4 sourceColor = sourcePixels[offsetX, offsetY].ToVector4(); - T packed = default(T); + TColor packed = default(TColor); packed.PackFromVector4(Vector4.Lerp(glowColor.ToVector4(), sourceColor, distance / maxDistance)); targetPixels[offsetX, offsetY] = packed; } diff --git a/src/ImageProcessorCore/Filters/Processors/InvertProcessor.cs b/src/ImageProcessorCore/Filters/Processors/InvertProcessor.cs index 54b85540e2..ca66ce4c3a 100644 --- a/src/ImageProcessorCore/Filters/Processors/InvertProcessor.cs +++ b/src/ImageProcessorCore/Filters/Processors/InvertProcessor.cs @@ -10,16 +10,16 @@ namespace ImageProcessorCore.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. long, float. - public class InvertProcessor : ImageProcessor - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class InvertProcessor : ImageProcessor + where TColor : IPackedVector + where TPacked : struct { /// - protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) + protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) { int startX = sourceRectangle.X; int endX = sourceRectangle.Right; @@ -42,8 +42,8 @@ namespace ImageProcessorCore.Processors startY = 0; } - using (IPixelAccessor sourcePixels = source.Lock()) - using (IPixelAccessor targetPixels = target.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock()) { Parallel.For( minY, @@ -58,7 +58,7 @@ namespace ImageProcessorCore.Processors Vector4 color = sourcePixels[offsetX, offsetY].ToVector4(); Vector3 vector = inverseVector - new Vector3(color.X, color.Y, color.Z); - T packed = default(T); + TColor packed = default(TColor); packed.PackFromVector4(new Vector4(vector, color.W)); targetPixels[offsetX, offsetY] = packed; } diff --git a/src/ImageProcessorCore/Filters/Processors/PixelateProcessor.cs b/src/ImageProcessorCore/Filters/Processors/PixelateProcessor.cs index b0348fb2b1..4e5c63ed4d 100644 --- a/src/ImageProcessorCore/Filters/Processors/PixelateProcessor.cs +++ b/src/ImageProcessorCore/Filters/Processors/PixelateProcessor.cs @@ -10,16 +10,16 @@ namespace ImageProcessorCore.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. long, float. - public class PixelateProcessor : ImageProcessor - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class PixelateProcessor : ImageProcessor + where TColor : IPackedVector + where TPacked : struct { /// - /// 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 +37,7 @@ namespace ImageProcessorCore.Processors public int Value { get; } /// - protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) + protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) { int startX = sourceRectangle.X; int endX = sourceRectangle.Right; @@ -64,8 +64,8 @@ namespace ImageProcessorCore.Processors // Get the range on the y-plane to choose from. IEnumerable range = EnumerableExtensions.SteppedRange(minY, i => i < maxY, size); - using (IPixelAccessor sourcePixels = source.Lock()) - using (IPixelAccessor targetPixels = target.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock()) { Parallel.ForEach( range, @@ -93,7 +93,7 @@ namespace ImageProcessorCore.Processors // Get the pixel color in the centre of the soon to be pixelated area. // ReSharper disable AccessToDisposedClosure - T pixel = sourcePixels[offsetX + offsetPx, offsetY + offsetPy]; + TColor pixel = sourcePixels[offsetX + offsetPx, offsetY + offsetPy]; // For each pixel in the pixelate size, set it to the centre color. for (int l = offsetY; l < offsetY + size && l < maxY; l++) diff --git a/src/ImageProcessorCore/Filters/Processors/VignetteProcessor.cs b/src/ImageProcessorCore/Filters/Processors/VignetteProcessor.cs index a7d466c891..c6e8cf35ea 100644 --- a/src/ImageProcessorCore/Filters/Processors/VignetteProcessor.cs +++ b/src/ImageProcessorCore/Filters/Processors/VignetteProcessor.cs @@ -10,20 +10,20 @@ namespace ImageProcessorCore.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. long, float. - public class VignetteProcessor : ImageProcessor - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class VignetteProcessor : ImageProcessor + where TColor : IPackedVector + where TPacked : struct { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// public VignetteProcessor() { - T color = default(T); + TColor color = default(TColor); color.PackFromVector4(Color.Black.ToVector4()); this.VignetteColor = color; } @@ -31,7 +31,7 @@ namespace ImageProcessorCore.Processors /// /// Gets or sets the vignette color to apply. /// - public T VignetteColor { get; set; } + public TColor VignetteColor { get; set; } /// /// Gets or sets the the x-radius. @@ -44,11 +44,11 @@ namespace ImageProcessorCore.Processors public float RadiusY { get; set; } /// - protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) + protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) { int startX = sourceRectangle.X; int endX = sourceRectangle.Right; - T vignetteColor = this.VignetteColor; + TColor vignetteColor = this.VignetteColor; Vector2 centre = Rectangle.Center(sourceRectangle).ToVector2(); float rX = this.RadiusX > 0 ? Math.Min(this.RadiusX, sourceRectangle.Width * .5F) : sourceRectangle.Width * .5F; float rY = this.RadiusY > 0 ? Math.Min(this.RadiusY, sourceRectangle.Height * .5F) : sourceRectangle.Height * .5F; @@ -71,8 +71,8 @@ namespace ImageProcessorCore.Processors startY = 0; } - using (IPixelAccessor sourcePixels = source.Lock()) - using (IPixelAccessor targetPixels = target.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock()) { Parallel.For( minY, @@ -86,7 +86,7 @@ namespace ImageProcessorCore.Processors int offsetX = x - startX; float distance = Vector2.Distance(centre, new Vector2(offsetX, offsetY)); Vector4 sourceColor = sourcePixels[offsetX, offsetY].ToVector4(); - T packed = default(T); + TColor packed = default(TColor); packed.PackFromVector4(Vector4.Lerp(vignetteColor.ToVector4(), sourceColor, 1 - (.9F * (distance / maxDistance)))); targetPixels[offsetX, offsetY] = packed; } diff --git a/src/ImageProcessorCore/Filters/Saturation.cs b/src/ImageProcessorCore/Filters/Saturation.cs index cdd2a1bc03..6e2367d806 100644 --- a/src/ImageProcessorCore/Filters/Saturation.cs +++ b/src/ImageProcessorCore/Filters/Saturation.cs @@ -8,22 +8,22 @@ namespace ImageProcessorCore using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Alters the saturation component of the image. /// - /// The pixel format. - /// The packed format. long, float. + /// 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. /// A delegate which is called as progress is made processing the image. - /// The . - public static Image Saturation(this Image source, int amount, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image Saturation(this Image source, int amount, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { return Saturation(source, amount, source.Bounds, progressHandler); } @@ -31,20 +31,20 @@ namespace ImageProcessorCore /// /// Alters the saturation component of the image. /// - /// The pixel format. - /// The packed format. long, float. + /// 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. /// /// A delegate which is called as progress is made processing the image. - /// The . - public static Image Saturation(this Image source, int amount, Rectangle rectangle, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image Saturation(this Image source, int amount, Rectangle rectangle, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { - SaturationProcessor processor = new SaturationProcessor(amount); + SaturationProcessor processor = new SaturationProcessor(amount); processor.OnProgress += progressHandler; try diff --git a/src/ImageProcessorCore/Filters/Sepia.cs b/src/ImageProcessorCore/Filters/Sepia.cs index 6a007d3b3b..750d3016fc 100644 --- a/src/ImageProcessorCore/Filters/Sepia.cs +++ b/src/ImageProcessorCore/Filters/Sepia.cs @@ -8,21 +8,21 @@ namespace ImageProcessorCore using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Applies sepia toning to the image. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image this method extends. /// A delegate which is called as progress is made processing the image. /// The . - public static Image Sepia(this Image source, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + public static Image Sepia(this Image source, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { return Sepia(source, source.Bounds, progressHandler); } @@ -30,19 +30,19 @@ namespace ImageProcessorCore /// /// Applies sepia toning to the image. /// - /// The pixel format. - /// The packed format. long, float. + /// 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. /// /// A delegate which is called as progress is made processing the image. /// The . - public static Image Sepia(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + public static Image Sepia(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { - SepiaProcessor processor = new SepiaProcessor(); + SepiaProcessor processor = new SepiaProcessor(); processor.OnProgress += progressHandler; try diff --git a/src/ImageProcessorCore/Filters/Vignette.cs b/src/ImageProcessorCore/Filters/Vignette.cs index f439297c32..f884db6131 100644 --- a/src/ImageProcessorCore/Filters/Vignette.cs +++ b/src/ImageProcessorCore/Filters/Vignette.cs @@ -8,37 +8,37 @@ namespace ImageProcessorCore using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Applies a radial vignette effect to an image. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image this method extends. /// A delegate which is called as progress is made processing the image. - /// The . - public static Image Vignette(this Image source, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image Vignette(this Image source, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { - return Vignette(source, default(T), source.Bounds.Width * .5F, source.Bounds.Height * .5F, source.Bounds, progressHandler); + return Vignette(source, default(TColor), source.Bounds.Width * .5F, source.Bounds.Height * .5F, source.Bounds, progressHandler); } /// /// Applies a radial vignette effect to an image. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image this method extends. /// The color to set as the vignette. /// A delegate which is called as progress is made processing the image. - /// The . - public static Image Vignette(this Image source, T color, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image Vignette(this Image source, TColor color, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { return Vignette(source, color, source.Bounds.Width * .5F, source.Bounds.Height * .5F, source.Bounds, progressHandler); } @@ -46,43 +46,43 @@ namespace ImageProcessorCore /// /// Applies a radial vignette effect to an image. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image this method extends. /// The the x-radius. /// The the y-radius. /// A delegate which is called as progress is made processing the image. - /// The . - public static Image Vignette(this Image source, float radiusX, float radiusY, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image Vignette(this Image source, float radiusX, float radiusY, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { - return Vignette(source, default(T), radiusX, radiusY, source.Bounds, progressHandler); + return Vignette(source, default(TColor), radiusX, radiusY, source.Bounds, progressHandler); } /// /// Applies a radial vignette effect to an image. /// - /// The pixel format. - /// The packed format. long, float. + /// 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. /// /// A delegate which is called as progress is made processing the image. - /// The . - public static Image Vignette(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image Vignette(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { - return Vignette(source, default(T), 0, 0, rectangle, progressHandler); + return Vignette(source, default(TColor), 0, 0, rectangle, progressHandler); } /// /// Applies a radial vignette effect to an image. /// - /// The pixel format. - /// The packed format. long, float. + /// 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. @@ -91,14 +91,14 @@ namespace ImageProcessorCore /// The structure that specifies the portion of the image object to alter. /// /// A delegate which is called as progress is made processing the image. - /// The . - public static Image Vignette(this Image source, T color, float radiusX, float radiusY, Rectangle rectangle, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image Vignette(this Image source, TColor color, float radiusX, float radiusY, Rectangle rectangle, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { - VignetteProcessor processor = new VignetteProcessor { RadiusX = radiusX, RadiusY = radiusY }; + VignetteProcessor processor = new VignetteProcessor { RadiusX = radiusX, RadiusY = radiusY }; - if (!color.Equals(default(T))) + if (!color.Equals(default(TColor))) { processor.VignetteColor = color; } diff --git a/src/ImageProcessorCore/Formats/Bmp/BmpDecoder.cs b/src/ImageProcessorCore/Formats/Bmp/BmpDecoder.cs index bd05cc7e86..c87de4cc05 100644 --- a/src/ImageProcessorCore/Formats/Bmp/BmpDecoder.cs +++ b/src/ImageProcessorCore/Formats/Bmp/BmpDecoder.cs @@ -70,9 +70,9 @@ namespace ImageProcessorCore.Formats } /// - public void Decode(Image image, Stream stream) - where T : IPackedVector - where TP : struct + public void Decode(Image image, Stream stream) + where TColor : IPackedVector + where TPacked : struct { Guard.NotNull(image, "image"); Guard.NotNull(stream, "stream"); diff --git a/src/ImageProcessorCore/Formats/Bmp/BmpDecoderCore.cs b/src/ImageProcessorCore/Formats/Bmp/BmpDecoderCore.cs index 50b131bb8d..82d7823f4e 100644 --- a/src/ImageProcessorCore/Formats/Bmp/BmpDecoderCore.cs +++ b/src/ImageProcessorCore/Formats/Bmp/BmpDecoderCore.cs @@ -49,20 +49,20 @@ namespace ImageProcessorCore.Formats /// Decodes the image from the specified this._stream and sets /// the data to image. /// - /// The pixel format. - /// The packed format. long, float. + /// 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 /// decoded from. Cannot be null (Nothing in Visual Basic). - /// + /// /// is null. /// - or - /// is null. /// - public void Decode(Image image, Stream stream) - where T : IPackedVector - where TP : struct + public void Decode(Image image, Stream stream) + where TColor : IPackedVector + where TPacked : struct { this.currentStream = stream; @@ -121,7 +121,7 @@ namespace ImageProcessorCore.Formats + $"bigger then the max allowed size '{image.MaxWidth}x{image.MaxHeight}'"); } - T[] imageData = new T[this.infoHeader.Width * this.infoHeader.Height]; + TColor[] imageData = new TColor[this.infoHeader.Width * this.infoHeader.Height]; switch (this.infoHeader.Compression) { @@ -134,19 +134,19 @@ namespace ImageProcessorCore.Formats if (this.infoHeader.BitsPerPixel == 32) { - this.ReadRgb32(imageData, this.infoHeader.Width, this.infoHeader.Height, inverted); + this.ReadRgb32(imageData, this.infoHeader.Width, this.infoHeader.Height, inverted); } else if (this.infoHeader.BitsPerPixel == 24) { - this.ReadRgb24(imageData, this.infoHeader.Width, this.infoHeader.Height, inverted); + this.ReadRgb24(imageData, this.infoHeader.Width, this.infoHeader.Height, inverted); } else if (this.infoHeader.BitsPerPixel == 16) { - this.ReadRgb16(imageData, this.infoHeader.Width, this.infoHeader.Height, inverted); + this.ReadRgb16(imageData, this.infoHeader.Width, this.infoHeader.Height, inverted); } else if (this.infoHeader.BitsPerPixel <= 8) { - this.ReadRgbPalette(imageData, palette, this.infoHeader.Width, this.infoHeader.Height, this.infoHeader.BitsPerPixel, inverted); + this.ReadRgbPalette(imageData, palette, this.infoHeader.Width, this.infoHeader.Height, this.infoHeader.BitsPerPixel, inverted); } break; @@ -188,17 +188,17 @@ namespace ImageProcessorCore.Formats /// /// Reads the color palette from the stream. /// - /// The pixel format. - /// The packed format. long, float. - /// The image data to assign the palette to. + /// The pixel format. + /// The packed format. uint, long, float. + /// The image data 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(T[] imageData, byte[] colors, int width, int height, int bits, bool inverted) - where T : IPackedVector - where TP : struct + private void ReadRgbPalette(TColor[] imageData, byte[] colors, int width, int height, int bits, bool inverted) + where TColor : IPackedVector + where TPacked : struct { // Pixels per byte (bits per pixel) int ppb = 8 / bits; @@ -242,7 +242,7 @@ namespace ImageProcessorCore.Formats int arrayOffset = (row * width) + (colOffset + shift); // Stored in b-> g-> r order. - T packed = default(T); + TColor packed = default(TColor); packed.PackFromBytes(colors[colorIndex + 2], colors[colorIndex + 1], colors[colorIndex], 255); imageData[arrayOffset] = packed; } @@ -253,15 +253,15 @@ namespace ImageProcessorCore.Formats /// /// Reads the 16 bit color palette from the stream /// - /// The pixel format. - /// The packed format. long, float. - /// The image data to assign the palette to. + /// The pixel format. + /// The packed format. uint, long, float. + /// The image data to assign the palette to. /// The width of the bitmap. /// The height of the bitmap. /// Whether the bitmap is inverted. - private void ReadRgb16(T[] imageData, int width, int height, bool inverted) - where T : IPackedVector - where TP : struct + private void ReadRgb16(TColor[] imageData, int width, int height, bool inverted) + where TColor : IPackedVector + where TPacked : struct { // We divide here as we will store the colors in our floating point format. const int ScaleR = 8; // 256/32 @@ -294,7 +294,7 @@ namespace ImageProcessorCore.Formats int arrayOffset = ((row * width) + x); // Stored in b-> g-> r order. - T packed = default(T); + TColor packed = default(TColor); packed.PackFromBytes(r, g, b, 255); imageData[arrayOffset] = packed; } @@ -304,15 +304,15 @@ namespace ImageProcessorCore.Formats /// /// Reads the 24 bit color palette from the stream /// - /// The pixel format. - /// The packed format. long, float. - /// The image data to assign the palette to. + /// The pixel format. + /// The packed format. uint, long, float. + /// The image data to assign the palette to. /// The width of the bitmap. /// The height of the bitmap. /// Whether the bitmap is inverted. - private void ReadRgb24(T[] imageData, int width, int height, bool inverted) - where T : IPackedVector - where TP : struct + private void ReadRgb24(TColor[] imageData, int width, int height, bool inverted) + where TColor : IPackedVector + where TPacked : struct { int alignment; byte[] data = this.GetImageArray(width, height, 3, out alignment); @@ -335,7 +335,7 @@ namespace ImageProcessorCore.Formats // We divide by 255 as we will store the colors in our floating point format. // Stored in b-> g-> r-> a order. - T packed = default(T); + TColor packed = default(TColor); packed.PackFromBytes(data[offset + 2], data[offset + 1], data[offset], 255); imageData[arrayOffset] = packed; } @@ -345,15 +345,15 @@ namespace ImageProcessorCore.Formats /// /// Reads the 32 bit color palette from the stream /// - /// The pixel format. - /// The packed format. long, float. - /// The image data to assign the palette to. + /// The pixel format. + /// The packed format. uint, long, float. + /// The image data to assign the palette to. /// The width of the bitmap. /// The height of the bitmap. /// Whether the bitmap is inverted. - private void ReadRgb32(T[] imageData, int width, int height, bool inverted) - where T : IPackedVector - where TP : struct + private void ReadRgb32(TColor[] imageData, int width, int height, bool inverted) + where TColor : IPackedVector + where TPacked : struct { int alignment; byte[] data = this.GetImageArray(width, height, 4, out alignment); @@ -375,7 +375,7 @@ namespace ImageProcessorCore.Formats int arrayOffset = ((row * width) + x); // Stored in b-> g-> r-> a order. - T packed = default(T); + TColor packed = default(TColor); packed.PackFromBytes(data[offset + 2], data[offset + 1], data[offset], data[offset + 3]); imageData[arrayOffset] = packed; } diff --git a/src/ImageProcessorCore/Formats/Bmp/BmpEncoder.cs b/src/ImageProcessorCore/Formats/Bmp/BmpEncoder.cs index 960869e9f6..9b19644198 100644 --- a/src/ImageProcessorCore/Formats/Bmp/BmpEncoder.cs +++ b/src/ImageProcessorCore/Formats/Bmp/BmpEncoder.cs @@ -43,9 +43,9 @@ namespace ImageProcessorCore.Formats } /// - public void Encode(Image image, Stream stream) - where T : IPackedVector - where TP : struct + public void Encode(Image image, Stream stream) + where TColor : IPackedVector + where TPacked : struct { BmpEncoderCore encoder = new BmpEncoderCore(); encoder.Encode(image, stream, this.BitsPerPixel); diff --git a/src/ImageProcessorCore/Formats/Bmp/BmpEncoderCore.cs b/src/ImageProcessorCore/Formats/Bmp/BmpEncoderCore.cs index 95cb55d369..5b959d8442 100644 --- a/src/ImageProcessorCore/Formats/Bmp/BmpEncoderCore.cs +++ b/src/ImageProcessorCore/Formats/Bmp/BmpEncoderCore.cs @@ -25,16 +25,16 @@ namespace ImageProcessorCore.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 pixel format. + /// The packed format. uint, long, float. + /// The to encode from. /// The to encode the image data to. /// The - public void Encode(ImageBase image, Stream stream, BmpBitsPerPixel bitsPerPixel) - where T : IPackedVector - where TP : struct + public void Encode(ImageBase image, Stream stream, BmpBitsPerPixel bitsPerPixel) + where TColor : IPackedVector + where TPacked : struct { Guard.NotNull(image, nameof(image)); Guard.NotNull(stream, nameof(stream)); @@ -119,17 +119,17 @@ namespace ImageProcessorCore.Formats /// /// Writes the pixel data to the binary stream. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The containing the stream to write to. /// - /// The containing pixel data. + /// The containing pixel data. /// - private void WriteImage(EndianBinaryWriter writer, ImageBase image) - where T : IPackedVector - where TP : struct + private void WriteImage(EndianBinaryWriter writer, ImageBase image) + where TColor : IPackedVector + where TPacked : struct { - using (IPixelAccessor pixels = image.Lock()) + using (PixelAccessor pixels = image.Lock()) { switch (this.bmpBitsPerPixel) { @@ -147,13 +147,13 @@ namespace ImageProcessorCore.Formats /// /// Writes the 32bit color palette to the stream. /// - /// The pixel format. - /// The packed format. long, float. + /// 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, IPixelAccessor pixels) - where T : IPackedVector - where TP : struct + private void Write32Bit(EndianBinaryWriter writer, PixelAccessor pixels) + where TColor : IPackedVector + where TPacked : struct { for (int y = pixels.Height - 1; y >= 0; y--) { @@ -175,12 +175,12 @@ namespace ImageProcessorCore.Formats /// /// Writes the 24bit color palette to the stream. /// - /// The pixel format. - /// The packed format. long, float./// The containing the stream to write to. + /// 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, IPixelAccessor pixels) - where T : IPackedVector - where TP : struct + private void Write24Bit(EndianBinaryWriter writer, PixelAccessor pixels) + where TColor : IPackedVector + where TPacked : struct { for (int y = pixels.Height - 1; y >= 0; y--) { diff --git a/src/ImageProcessorCore/Formats/Gif/GifDecoder.cs b/src/ImageProcessorCore/Formats/Gif/GifDecoder.cs index 3f73510ca7..874dc694f8 100644 --- a/src/ImageProcessorCore/Formats/Gif/GifDecoder.cs +++ b/src/ImageProcessorCore/Formats/Gif/GifDecoder.cs @@ -55,11 +55,11 @@ namespace ImageProcessorCore.Formats } /// - public void Decode(Image image, Stream stream) - where T : IPackedVector - where TP : struct + public void Decode(Image image, Stream stream) + where TColor : IPackedVector + where TPacked : struct { - new GifDecoderCore().Decode(image, stream); + new GifDecoderCore().Decode(image, stream); } } } diff --git a/src/ImageProcessorCore/Formats/Gif/GifDecoderCore.cs b/src/ImageProcessorCore/Formats/Gif/GifDecoderCore.cs index f981c0c290..d37bca929a 100644 --- a/src/ImageProcessorCore/Formats/Gif/GifDecoderCore.cs +++ b/src/ImageProcessorCore/Formats/Gif/GifDecoderCore.cs @@ -11,16 +11,16 @@ namespace ImageProcessorCore.Formats /// /// Performs the gif decoding operation. /// - /// The pixel format. - /// The packed format. long, float. - internal class GifDecoderCore - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + internal class GifDecoderCore + where TColor : IPackedVector + where TPacked : struct { /// /// The image to decode the information to. /// - private Image decodedImage; + private Image decodedImage; /// /// The currently loaded stream. @@ -35,7 +35,7 @@ namespace ImageProcessorCore.Formats /// /// The current frame. /// - private T[] currentFrame; + private TColor[] currentFrame; /// /// The logical screen descriptor. @@ -52,7 +52,7 @@ namespace ImageProcessorCore.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) { this.decodedImage = image; @@ -292,15 +292,15 @@ namespace ImageProcessorCore.Formats if (this.currentFrame == null) { - this.currentFrame = new T[imageWidth * imageHeight]; + this.currentFrame = new TColor[imageWidth * imageHeight]; } - T[] lastFrame = null; + TColor[] lastFrame = null; if (this.graphicsControlExtension != null && this.graphicsControlExtension.DisposalMethod == DisposalMethod.RestoreToPrevious) { - lastFrame = new T[imageWidth * imageHeight]; + lastFrame = new TColor[imageWidth * imageHeight]; Array.Copy(this.currentFrame, lastFrame, lastFrame.Length); } @@ -359,7 +359,7 @@ namespace ImageProcessorCore.Formats // Stored in r-> g-> b-> a order. int indexOffset = index * 3; - T pixel = default(T); + TColor pixel = default(TColor); pixel.PackFromBytes(colorTable[indexOffset], colorTable[indexOffset + 1], colorTable[indexOffset + 2], 255); this.currentFrame[offset] = pixel; } @@ -368,11 +368,11 @@ namespace ImageProcessorCore.Formats } } - T[] pixels = new T[imageWidth * imageHeight]; + TColor[] pixels = new TColor[imageWidth * imageHeight]; Array.Copy(this.currentFrame, pixels, pixels.Length); - ImageBase currentImage; + ImageBase currentImage; if (this.decodedImage.Pixels == null) { @@ -387,7 +387,7 @@ namespace ImageProcessorCore.Formats } else { - ImageFrame frame = new ImageFrame(); + ImageFrame frame = new ImageFrame(); currentImage = frame; currentImage.SetPixels(imageWidth, imageHeight, pixels); @@ -412,7 +412,7 @@ namespace ImageProcessorCore.Formats offset = (y * imageWidth) + x; // Stored in r-> g-> b-> a order. - this.currentFrame[offset] = default(T); + this.currentFrame[offset] = default(TColor); } } } diff --git a/src/ImageProcessorCore/Formats/Gif/GifEncoder.cs b/src/ImageProcessorCore/Formats/Gif/GifEncoder.cs index af3475ea25..d53cf21083 100644 --- a/src/ImageProcessorCore/Formats/Gif/GifEncoder.cs +++ b/src/ImageProcessorCore/Formats/Gif/GifEncoder.cs @@ -47,9 +47,9 @@ namespace ImageProcessorCore.Formats } /// - public void Encode(Image image, Stream stream) - where T : IPackedVector - where TP : struct + public void Encode(Image image, Stream stream) + where TColor : IPackedVector + where TPacked : struct { GifEncoderCore encoder = new GifEncoderCore { diff --git a/src/ImageProcessorCore/Formats/Gif/GifEncoderCore.cs b/src/ImageProcessorCore/Formats/Gif/GifEncoderCore.cs index 35cb28e0ef..cf4d39a89c 100644 --- a/src/ImageProcessorCore/Formats/Gif/GifEncoderCore.cs +++ b/src/ImageProcessorCore/Formats/Gif/GifEncoderCore.cs @@ -40,22 +40,22 @@ namespace ImageProcessorCore.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. long, float. - /// The to encode from. + /// The pixel format. + /// The packed format. uint, long, float. + /// The to encode from. /// The to encode the image data to. - public void Encode(Image image, Stream stream) - where T : IPackedVector - where TP : struct + public void Encode(Image image, Stream stream) + where TColor : IPackedVector + where TPacked : struct { Guard.NotNull(image, nameof(image)); Guard.NotNull(stream, nameof(stream)); if (this.Quantizer == null) { - this.Quantizer = new OctreeQuantizer { Threshold = this.Threshold }; + this.Quantizer = new OctreeQuantizer { Threshold = this.Threshold }; } // Do not use IDisposable pattern here as we want to preserve the stream. @@ -69,7 +69,7 @@ namespace ImageProcessorCore.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); // Write the header. this.WriteHeader(writer); @@ -87,9 +87,9 @@ namespace ImageProcessorCore.Formats if (image.Frames.Any()) { this.WriteApplicationExtension(writer, image.RepeatCount, image.Frames.Count); - foreach (ImageFrame frame in image.Frames) + foreach (ImageFrame frame in image.Frames) { - QuantizedImage quantizedFrame = ((IQuantizer)this.Quantizer).Quantize(frame, this.Quality); + QuantizedImage quantizedFrame = ((IQuantizer)this.Quantizer).Quantize(frame, this.Quality); this.WriteGraphicalControlExtension(frame, writer, quantizedFrame.TransparentIndex); this.WriteImageDescriptor(frame, writer); this.WriteColorTable(quantizedFrame, writer); @@ -113,14 +113,14 @@ namespace ImageProcessorCore.Formats /// /// Writes the logical screen descriptor to the stream. /// - /// The pixel format. - /// The packed format. long, float. + /// 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 backgound index to. - private void WriteLogicalScreenDescriptor(Image image, EndianBinaryWriter writer, int tranparencyIndex) - where T : IPackedVector - where TP : struct + private void WriteLogicalScreenDescriptor(Image image, EndianBinaryWriter writer, int tranparencyIndex) + where TColor : IPackedVector + where TPacked : struct { GifLogicalScreenDescriptor descriptor = new GifLogicalScreenDescriptor { @@ -186,14 +186,14 @@ namespace ImageProcessorCore.Formats /// /// Writes the graphics control extension to the stream. /// - /// The pixel format. - /// The packed format. long, float. - /// The to encode. + /// The pixel format. + /// The packed format. uint, long, float. + /// 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 T : IPackedVector - where TP : struct + private void WriteGraphicalControlExtension(ImageBase image, EndianBinaryWriter writer, int transparencyIndex) + where TColor : IPackedVector + where TPacked : struct { // TODO: Check transparency logic. bool hasTransparent = transparencyIndex > -1; @@ -234,13 +234,13 @@ namespace ImageProcessorCore.Formats /// /// Writes the image descriptor to the stream. /// - /// The pixel format. - /// The packed format. long, float. - /// The to be encoded. + /// The pixel format. + /// The packed format. uint, long, float. + /// The to be encoded. /// The stream to write to. - private void WriteImageDescriptor(ImageBase image, EndianBinaryWriter writer) - where T : IPackedVector - where TP : struct + private void WriteImageDescriptor(ImageBase image, EndianBinaryWriter writer) + where TColor : IPackedVector + where TPacked : struct { writer.Write(GifConstants.ImageDescriptorLabel); // 2c // TODO: Can we capture this? @@ -261,16 +261,16 @@ namespace ImageProcessorCore.Formats /// /// Writes the color table to the stream. /// - /// The pixel format. - /// The packed format. long, float. - /// The to encode. + /// The pixel format. + /// The packed format. uint, long, float. + /// The to encode. /// The writer to write to the stream with. - private void WriteColorTable(QuantizedImage image, EndianBinaryWriter writer) - where T : IPackedVector - where TP : struct + private void WriteColorTable(QuantizedImage image, EndianBinaryWriter writer) + where TColor : IPackedVector + where TPacked : struct { // Grab the palette and write it to the stream. - T[] palette = image.Palette; + TColor[] palette = image.Palette; int pixelCount = palette.Length; // Get max colors for bit depth. @@ -294,13 +294,13 @@ namespace ImageProcessorCore.Formats /// /// Writes the image pixel data to the stream. /// - /// The pixel format. - /// The packed format. long, float. - /// The containing indexed pixels. + /// The pixel format. + /// The packed format. uint, long, float. + /// The containing indexed pixels. /// The stream to write to. - private void WriteImageData(QuantizedImage image, EndianBinaryWriter writer) - where T : IPackedVector - where TP : struct + private void WriteImageData(QuantizedImage image, EndianBinaryWriter writer) + where TColor : IPackedVector + where TPacked : struct { byte[] indexedPixels = image.Pixels; diff --git a/src/ImageProcessorCore/Formats/Gif/LzwDecoder.cs b/src/ImageProcessorCore/Formats/Gif/LzwDecoder.cs index 75d590673a..1474cc7089 100644 --- a/src/ImageProcessorCore/Formats/Gif/LzwDecoder.cs +++ b/src/ImageProcessorCore/Formats/Gif/LzwDecoder.cs @@ -33,7 +33,7 @@ namespace ImageProcessorCore.Formats /// and sets the stream, where the compressed data should be read from. /// /// The stream to read from. - /// is null. + /// is null. public LzwDecoder(Stream stream) { Guard.NotNull(stream, nameof(stream)); diff --git a/src/ImageProcessorCore/Formats/Gif/LzwEncoder.cs b/src/ImageProcessorCore/Formats/Gif/LzwEncoder.cs index a9681d2c56..469cacbcea 100644 --- a/src/ImageProcessorCore/Formats/Gif/LzwEncoder.cs +++ b/src/ImageProcessorCore/Formats/Gif/LzwEncoder.cs @@ -310,7 +310,7 @@ namespace ImageProcessorCore.Formats } /// - /// Return the next pixel from the image + /// Return the nexTColor pixel from the image /// /// /// The diff --git a/src/ImageProcessorCore/Formats/Gif/Sections/GifGraphicsControlExtension.cs b/src/ImageProcessorCore/Formats/Gif/Sections/GifGraphicsControlExtension.cs index 071dc62c84..59dbceb21d 100644 --- a/src/ImageProcessorCore/Formats/Gif/Sections/GifGraphicsControlExtension.cs +++ b/src/ImageProcessorCore/Formats/Gif/Sections/GifGraphicsControlExtension.cs @@ -27,7 +27,7 @@ namespace ImageProcessorCore.Formats /// /// Gets or sets the transparency index. /// The Transparency Index is such that when encountered, the corresponding pixel - /// of the display device is not modified and processing goes on to the next pixel. + /// of the display device is not modified and processing goes on to the nexTColor pixel. /// public int TransparencyIndex { get; set; } diff --git a/src/ImageProcessorCore/Formats/IImageDecoder.cs b/src/ImageProcessorCore/Formats/IImageDecoder.cs index 8f9050905b..da1b819194 100644 --- a/src/ImageProcessorCore/Formats/IImageDecoder.cs +++ b/src/ImageProcessorCore/Formats/IImageDecoder.cs @@ -39,14 +39,14 @@ namespace ImageProcessorCore.Formats bool IsSupportedFileFormat(byte[] header); /// - /// Decodes the image from the specified stream to the . + /// Decodes the image from the specified stream to the . /// - /// The pixel format. - /// The packed format. long, float. - /// The to decode to. + /// The pixel format. + /// The packed format. uint, long, float. + /// The to decode to. /// The containing image data. - void Decode(Image image, Stream stream) - where T : IPackedVector - where TP : struct; + void Decode(Image image, Stream stream) + where TColor : IPackedVector + where TPacked : struct; } } diff --git a/src/ImageProcessorCore/Formats/IImageEncoder.cs b/src/ImageProcessorCore/Formats/IImageEncoder.cs index 09b2fca7dd..8083714563 100644 --- a/src/ImageProcessorCore/Formats/IImageEncoder.cs +++ b/src/ImageProcessorCore/Formats/IImageEncoder.cs @@ -40,12 +40,12 @@ namespace ImageProcessorCore.Formats /// /// Encodes the image to the specified stream from the . /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The to encode from. /// The to encode the image data to. - void Encode(Image image, Stream stream) - where T : IPackedVector - where TP : struct; + void Encode(Image image, Stream stream) + where TColor : IPackedVector + where TPacked : struct; } } diff --git a/src/ImageProcessorCore/Formats/Jpg/JpegDecoder.cs b/src/ImageProcessorCore/Formats/Jpg/JpegDecoder.cs index 84e46d5a4c..5f6869ddfd 100644 --- a/src/ImageProcessorCore/Formats/Jpg/JpegDecoder.cs +++ b/src/ImageProcessorCore/Formats/Jpg/JpegDecoder.cs @@ -76,9 +76,9 @@ namespace ImageProcessorCore.Formats } /// - public void Decode(Image image, Stream stream) - where T : IPackedVector - where TP : struct + public void Decode(Image image, Stream stream) + where TColor : IPackedVector + where TPacked : struct { Guard.NotNull(image, "image"); Guard.NotNull(stream, "stream"); diff --git a/src/ImageProcessorCore/Formats/Jpg/JpegDecoderCore.cs.REMOVED.git-id b/src/ImageProcessorCore/Formats/Jpg/JpegDecoderCore.cs.REMOVED.git-id index ae3ffc69d5..bd65b87026 100644 --- a/src/ImageProcessorCore/Formats/Jpg/JpegDecoderCore.cs.REMOVED.git-id +++ b/src/ImageProcessorCore/Formats/Jpg/JpegDecoderCore.cs.REMOVED.git-id @@ -1 +1 @@ -09f4618eaade2900f7174b9ab400deb0a25bd813 \ No newline at end of file +d6ce5dd6236ac6ef9ba570fb4e57e81c06bbb854 \ No newline at end of file diff --git a/src/ImageProcessorCore/Formats/Jpg/JpegEncoder.cs b/src/ImageProcessorCore/Formats/Jpg/JpegEncoder.cs index 72b7eace18..83f87acb72 100644 --- a/src/ImageProcessorCore/Formats/Jpg/JpegEncoder.cs +++ b/src/ImageProcessorCore/Formats/Jpg/JpegEncoder.cs @@ -78,9 +78,9 @@ namespace ImageProcessorCore.Formats } /// - public void Encode(Image image, Stream stream) - where T : IPackedVector - where TP : struct + public void Encode(Image image, Stream stream) + where TColor : IPackedVector + where TPacked : struct { JpegEncoderCore encode = new JpegEncoderCore(); if (this.subsampleSet) diff --git a/src/ImageProcessorCore/Formats/Jpg/JpegEncoderCore.cs b/src/ImageProcessorCore/Formats/Jpg/JpegEncoderCore.cs index cc7dfa7f9e..783406a28c 100644 --- a/src/ImageProcessorCore/Formats/Jpg/JpegEncoderCore.cs +++ b/src/ImageProcessorCore/Formats/Jpg/JpegEncoderCore.cs @@ -339,9 +339,9 @@ namespace ImageProcessorCore.Formats // toYCbCr converts the 8x8 region of m whose top-left corner is p to its // YCbCr values. - private void ToYCbCr(IPixelAccessor pixels, int x, int y, Block yBlock, Block cbBlock, Block crBlock) - where T : IPackedVector - where TP : struct + private void ToYCbCr(PixelAccessor pixels, int x, int y, Block yBlock, Block cbBlock, Block crBlock) + where TColor : IPackedVector + where TPacked : struct { int xmax = pixels.Width - 1; int ymax = pixels.Height - 1; @@ -430,9 +430,9 @@ namespace ImageProcessorCore.Formats // Encode writes the Image m to w in JPEG 4:2:0 baseline format with the given // options. Default parameters are used if a nil *Options is passed. - public void Encode(Image image, Stream stream, int quality, JpegSubsample sample) - where T : IPackedVector - where TP : struct + public void Encode(Image image, Stream stream, int quality, JpegSubsample sample) + where TColor : IPackedVector + where TPacked : struct { Guard.NotNull(image, nameof(image)); Guard.NotNull(stream, nameof(stream)); @@ -502,7 +502,7 @@ namespace ImageProcessorCore.Formats this.WriteDHT(componentCount); // Write the image data. - using (IPixelAccessor pixels = image.Lock()) + using (PixelAccessor pixels = image.Lock()) { this.WriteSOS(pixels); } @@ -570,9 +570,9 @@ namespace ImageProcessorCore.Formats this.outputStream.Write(this.buffer, 0, 4); } - private void WriteProfiles(Image image) - where T : IPackedVector - where TP : struct + private void WriteProfiles(Image image) + where TColor : IPackedVector + where TPacked : struct { WriteProfile(image.ExifProfile); } @@ -710,9 +710,9 @@ namespace ImageProcessorCore.Formats /// Writes the StartOfScan marker. /// /// The pixel accessor providing acces to the image pixels. - private void WriteSOS(IPixelAccessor pixels) - where T : IPackedVector - where TP : struct + private void WriteSOS(PixelAccessor pixels) + where TColor : IPackedVector + where TPacked : struct { // TODO: We should allow grayscale writing. this.outputStream.Write(this.SOSHeaderYCbCr, 0, this.SOSHeaderYCbCr.Length); @@ -737,9 +737,9 @@ namespace ImageProcessorCore.Formats /// Encodes the image with no subsampling. /// /// The pixel accessor providing acces to the image pixels. - private void Encode444(IPixelAccessor pixels) - where T : IPackedVector - where TP : struct + private void Encode444(PixelAccessor pixels) + where TColor : IPackedVector + where TPacked : struct { Block b = new Block(); Block cb = new Block(); @@ -763,9 +763,9 @@ namespace ImageProcessorCore.Formats /// at a factor of 2 both horizontally and vertically. /// /// The pixel accessor providing acces to the image pixels. - private void Encode420(IPixelAccessor pixels) - where T : IPackedVector - where TP : struct + private void Encode420(PixelAccessor pixels) + where TColor : IPackedVector + where TPacked : struct { Block b = new Block(); Block[] cb = new Block[4]; diff --git a/src/ImageProcessorCore/Formats/Png/Filters/UpFilter.cs b/src/ImageProcessorCore/Formats/Png/Filters/UpFilter.cs index 8f87ec1ca1..deb4d9d0d8 100644 --- a/src/ImageProcessorCore/Formats/Png/Filters/UpFilter.cs +++ b/src/ImageProcessorCore/Formats/Png/Filters/UpFilter.cs @@ -6,7 +6,7 @@ namespace ImageProcessorCore.Formats { /// - /// The Up filter is just like the Sub filter except that the pixel immediately above the current pixel, + /// The Up filter is just like the Sub filter except that the pixel immediately above the currenTColor pixel, /// rather than just to its left, is used as the predictor. /// /// diff --git a/src/ImageProcessorCore/Formats/Png/PngDecoder.cs b/src/ImageProcessorCore/Formats/Png/PngDecoder.cs index b2630fb36d..264971e4d5 100644 --- a/src/ImageProcessorCore/Formats/Png/PngDecoder.cs +++ b/src/ImageProcessorCore/Formats/Png/PngDecoder.cs @@ -75,13 +75,13 @@ namespace ImageProcessorCore.Formats } /// - /// Decodes the image from the specified stream to the . + /// Decodes the image from the specified stream to the . /// - /// The to decode to. + /// The to decode to. /// The containing image data. - public void Decode(Image image, Stream stream) - where T : IPackedVector - where TP : struct + public void Decode(Image image, Stream stream) + where TColor : IPackedVector + where TPacked : struct { new PngDecoderCore().Decode(image, stream); } diff --git a/src/ImageProcessorCore/Formats/Png/PngDecoderCore.cs b/src/ImageProcessorCore/Formats/Png/PngDecoderCore.cs index 2e8f81c19b..3cf8be40eb 100644 --- a/src/ImageProcessorCore/Formats/Png/PngDecoderCore.cs +++ b/src/ImageProcessorCore/Formats/Png/PngDecoderCore.cs @@ -80,8 +80,8 @@ namespace ImageProcessorCore.Formats /// /// Decodes the stream to the image. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image to decode to. /// The stream containing image data. /// @@ -90,11 +90,11 @@ namespace ImageProcessorCore.Formats /// /// Thrown if the image is larger than the maximum allowable size. /// - public void Decode(Image image, Stream stream) - where T : IPackedVector - where TP : struct + public void Decode(Image image, Stream stream) + where TColor : IPackedVector + where TPacked : struct { - Image currentImage = image; + Image currentImage = image; this.currentStream = stream; this.currentStream.Seek(8, SeekOrigin.Current); @@ -149,10 +149,10 @@ namespace ImageProcessorCore.Formats + $"max allowed size '{image.MaxWidth}x{image.MaxHeight}'"); } - T[] pixels = new T[this.header.Width * this.header.Height]; + TColor[] pixels = new TColor[this.header.Width * this.header.Height]; - this.ReadScanlines(dataStream, pixels); + this.ReadScanlines(dataStream, pixels); image.SetPixels(this.header.Width, this.header.Height, pixels); @@ -162,13 +162,13 @@ namespace ImageProcessorCore.Formats /// /// Reads the data chunk containing physical dimension data. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image to read to. /// The data containing physical data. - private void ReadPhysicalChunk(Image image, byte[] data) - where T : IPackedVector - where TP : struct + private void ReadPhysicalChunk(Image image, byte[] data) + where TColor : IPackedVector + where TPacked : struct { Array.Reverse(data, 0, 4); Array.Reverse(data, 4, 4); @@ -228,10 +228,10 @@ namespace ImageProcessorCore.Formats /// /// The containing data. /// - /// The containing pixel data. - private void ReadScanlines(MemoryStream dataStream, T[] pixels) - where T : IPackedVector - where TP : struct + /// The containing pixel data. + private void ReadScanlines(MemoryStream dataStream, TColor[] pixels) + where TColor : IPackedVector + where TPacked : struct { this.bytesPerPixel = this.CalculateBytesPerPixel(); this.bytesPerScanline = this.CalculateScanlineLength() + 1; @@ -250,7 +250,7 @@ namespace ImageProcessorCore.Formats decompressedStream.Flush(); byte[] decompressedBytes = decompressedStream.ToArray(); - DecodePixelData(decompressedBytes, pixels); + DecodePixelData(decompressedBytes, pixels); } } } @@ -258,13 +258,13 @@ namespace ImageProcessorCore.Formats /// /// Decodes the raw pixel data row by row /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The pixel data. /// The image pixels. - private void DecodePixelData(byte[] pixelData, T[] pixels) - where T : IPackedVector - where TP : struct + private void DecodePixelData(byte[] pixelData, TColor[] pixels) + where TColor : IPackedVector + where TPacked : struct { byte[] previousScanline = new byte[this.bytesPerScanline]; @@ -312,21 +312,21 @@ namespace ImageProcessorCore.Formats } previousScanline = defilteredScanline; - ProcessDefilteredScanline(defilteredScanline, y, pixels); + ProcessDefilteredScanline(defilteredScanline, y, pixels); } } /// /// Processes the defiltered scanline filling the image pixel data /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// /// The current image row. /// The image pixels - private void ProcessDefilteredScanline(byte[] defilteredScanline, int row, T[] pixels) - where T : IPackedVector - where TP : struct + private void ProcessDefilteredScanline(byte[] defilteredScanline, int row, TColor[] pixels) + where TColor : IPackedVector + where TPacked : struct { switch (this.PngColorType) { @@ -338,7 +338,7 @@ namespace ImageProcessorCore.Formats byte intensity = defilteredScanline[offset]; - T color = default(T); + TColor color = default(TColor); color.PackFromBytes(intensity, intensity, intensity, 255); pixels[(row * this.header.Width) + x] = color; } @@ -354,7 +354,7 @@ namespace ImageProcessorCore.Formats byte intensity = defilteredScanline[offset]; byte alpha = defilteredScanline[offset + bytesPerSample]; - T color = default(T); + TColor color = default(TColor); color.PackFromBytes(intensity, intensity, intensity, alpha); pixels[(row * this.header.Width) + x] = color; } @@ -376,7 +376,7 @@ namespace ImageProcessorCore.Formats int pixelOffset = index * 3; byte a = this.paletteAlpha.Length > index ? this.paletteAlpha[index] : (byte)255; - T color = default(T); + TColor color = default(TColor); if (a > 0) { byte r = this.palette[pixelOffset]; @@ -400,7 +400,7 @@ namespace ImageProcessorCore.Formats byte g = this.palette[pixelOffset + 1]; byte b = this.palette[pixelOffset + 2]; - T color = default(T); + TColor color = default(TColor); color.PackFromBytes(r, g, b, 255); pixels[offset] = color; } @@ -418,7 +418,7 @@ namespace ImageProcessorCore.Formats byte g = defilteredScanline[offset + bytesPerSample]; byte b = defilteredScanline[offset + 2 * bytesPerSample]; - T color = default(T); + TColor color = default(TColor); color.PackFromBytes(r, g, b, 255); pixels[(row * this.header.Width) + x] = color; } @@ -436,7 +436,7 @@ namespace ImageProcessorCore.Formats byte b = defilteredScanline[offset + 2 * bytesPerSample]; byte a = defilteredScanline[offset + 3 * bytesPerSample]; - T color = default(T); + TColor color = default(TColor); color.PackFromBytes(r, g, b, a); pixels[(row * this.header.Width) + x] = color; } @@ -451,13 +451,13 @@ namespace ImageProcessorCore.Formats /// /// Reads a text chunk containing image properties from the data. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image to decode to. /// The containing data. - private void ReadTextChunk(Image image, byte[] data) - where T : IPackedVector - where TP : struct + private void ReadTextChunk(Image image, byte[] data) + where TColor : IPackedVector + where TPacked : struct { int zeroIndex = 0; diff --git a/src/ImageProcessorCore/Formats/Png/PngEncoder.cs b/src/ImageProcessorCore/Formats/Png/PngEncoder.cs index abe487d40c..660315c584 100644 --- a/src/ImageProcessorCore/Formats/Png/PngEncoder.cs +++ b/src/ImageProcessorCore/Formats/Png/PngEncoder.cs @@ -72,9 +72,9 @@ namespace ImageProcessorCore.Formats } /// - public void Encode(Image image, Stream stream) - where T : IPackedVector - where TP : struct + public void Encode(Image image, Stream stream) + where TColor : IPackedVector + where TPacked : struct { PngEncoderCore encoder = new PngEncoderCore { diff --git a/src/ImageProcessorCore/Formats/Png/PngEncoderCore.cs b/src/ImageProcessorCore/Formats/Png/PngEncoderCore.cs index 97ab62dff6..f666f0f0ee 100644 --- a/src/ImageProcessorCore/Formats/Png/PngEncoderCore.cs +++ b/src/ImageProcessorCore/Formats/Png/PngEncoderCore.cs @@ -89,15 +89,15 @@ namespace ImageProcessorCore.Formats public byte Threshold { get; set; } = 128; /// - /// 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 pixel format. + /// The packed format. uint, long, float. + /// The to encode from. /// The to encode the image data to. - public void Encode(ImageBase image, Stream stream) - where T : IPackedVector - where TP : struct + public void Encode(ImageBase image, Stream stream) + where TColor : IPackedVector + where TPacked : struct { Guard.NotNull(image, nameof(image)); Guard.NotNull(stream, nameof(stream)); @@ -185,34 +185,34 @@ namespace ImageProcessorCore.Formats /// /// Collects the indexed pixel data. /// - /// The pixel format. - /// The packed format. long, float. + /// 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 T : IPackedVector - where TP : struct + private void CollectIndexedBytes(ImageBase image, Stream stream, PngHeader header) + where TColor : IPackedVector + where TPacked : struct { // Quatize the image and get the pixels - QuantizedImage quantized = this.WritePaletteChunk(stream, header, image); + QuantizedImage quantized = this.WritePaletteChunk(stream, header, image); pixelData = quantized.Pixels; } /// /// Collects the grayscale pixel data. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image to encode. - private void CollectGrayscaleBytes(ImageBase image) - where T : IPackedVector - where TP : struct + private void CollectGrayscaleBytes(ImageBase image) + where TColor : IPackedVector + where TPacked : struct { // Copy the pixels across from the image. this.pixelData = new byte[this.width * this.height * this.bytesPerPixel]; int stride = this.width * this.bytesPerPixel; - using (IPixelAccessor pixels = image.Lock()) + using (PixelAccessor pixels = image.Lock()) { Parallel.For( 0, @@ -246,17 +246,17 @@ namespace ImageProcessorCore.Formats /// /// Collects the true color pixel data. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image to encode. - private void CollectColorBytes(ImageBase image) - where T : IPackedVector - where TP : struct + private void CollectColorBytes(ImageBase image) + where TColor : IPackedVector + where TPacked : struct { // Copy the pixels across from the image. this.pixelData = new byte[this.width * this.height * this.bytesPerPixel]; int stride = this.width * this.bytesPerPixel; - using (IPixelAccessor pixels = image.Lock()) + using (PixelAccessor pixels = image.Lock()) { Parallel.For( 0, @@ -474,14 +474,14 @@ namespace ImageProcessorCore.Formats /// /// Writes the palette chunk to the stream. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The containing image data. /// The . /// The image to encode. - private QuantizedImage WritePaletteChunk(Stream stream, PngHeader header, ImageBase image) - where T : IPackedVector - where TP : struct + private QuantizedImage WritePaletteChunk(Stream stream, PngHeader header, ImageBase image) + where TColor : IPackedVector + where TPacked : struct { if (this.Quality > 256) { @@ -490,14 +490,14 @@ namespace ImageProcessorCore.Formats if (this.Quantizer == null) { - this.Quantizer = new WuQuantizer { Threshold = this.Threshold }; + this.Quantizer = new WuQuantizer { Threshold = this.Threshold }; } // 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. - T[] palette = quantized.Palette; + TColor[] palette = quantized.Palette; int pixelCount = palette.Length; // Get max colors for bit depth. @@ -533,15 +533,15 @@ namespace ImageProcessorCore.Formats /// /// Writes the physical dimension information to the stream. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The containing image data. /// The image base. - private void WritePhysicalChunk(Stream stream, ImageBase imageBase) - where T : IPackedVector - where TP : struct + private void WritePhysicalChunk(Stream stream, ImageBase imageBase) + where TColor : IPackedVector + where TPacked : struct { - 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. diff --git a/src/ImageProcessorCore/IO/EndianBinaryWriter.cs b/src/ImageProcessorCore/IO/EndianBinaryWriter.cs index 0f37b9a13d..400f46f8d5 100644 --- a/src/ImageProcessorCore/IO/EndianBinaryWriter.cs +++ b/src/ImageProcessorCore/IO/EndianBinaryWriter.cs @@ -306,7 +306,7 @@ namespace ImageProcessorCore.IO /// Writes a string to the stream, using the encoding for this writer. /// /// The value to write. Must not be null. - /// value is null + /// value is null public void Write(string value) { if (value == null) diff --git a/src/ImageProcessorCore/IO/EndianBitConverter.cs b/src/ImageProcessorCore/IO/EndianBitConverter.cs index d95527002b..71cba1a513 100644 --- a/src/ImageProcessorCore/IO/EndianBitConverter.cs +++ b/src/ImageProcessorCore/IO/EndianBitConverter.cs @@ -245,7 +245,7 @@ namespace ImageProcessorCore.IO /// The byte array passed in /// The start index passed in /// The number of bytes required - /// value is a null reference + /// value is a null reference /// /// startIndex is less than zero or greater than the length of value minus bytesRequired. /// diff --git a/src/ImageProcessorCore/Image.cs b/src/ImageProcessorCore/Image.cs index e4e2186b97..0198403669 100644 --- a/src/ImageProcessorCore/Image.cs +++ b/src/ImageProcessorCore/Image.cs @@ -40,7 +40,7 @@ namespace ImageProcessorCore /// /// The stream containing image information. /// - /// Thrown if the is null. + /// Thrown if the is null. public Image(Stream stream) : base(stream) { @@ -51,7 +51,7 @@ namespace ImageProcessorCore /// by making a copy from another image. /// /// The other image, where the clone should be made from. - /// is null. + /// is null. public Image(Image other) : base(other) { diff --git a/src/ImageProcessorCore/Image/IImageBase.cs b/src/ImageProcessorCore/Image/IImageBase.cs index 3a4444b5e9..1afd7daaf8 100644 --- a/src/ImageProcessorCore/Image/IImageBase.cs +++ b/src/ImageProcessorCore/Image/IImageBase.cs @@ -10,16 +10,16 @@ namespace ImageProcessorCore /// /// Encapsulates the basic properties and methods required to manipulate images in varying formats. /// - /// The pixel format. - /// The packed format. long, float. - public interface IImageBase : IImageBase - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public interface IImageBase : IImageBase + where TColor : IPackedVector + where TPacked : struct { /// /// Gets the pixels as an array of the given packed pixel format. /// - T[] Pixels { get; } + TColor[] Pixels { get; } /// /// Sets the pixel array of the image to the given value. @@ -33,7 +33,7 @@ namespace ImageProcessorCore /// /// Thrown if the length is not equal to Width * Height. /// - void SetPixels(int width, int height, T[] pixels); + void SetPixels(int width, int height, TColor[] pixels); /// /// Sets the pixel array of the image to the given value, creating a copy of @@ -48,7 +48,7 @@ namespace ImageProcessorCore /// /// Thrown if the length is not equal to Width * Height. /// - void ClonePixels(int width, int height, T[] pixels); + void ClonePixels(int width, int height, TColor[] pixels); /// /// Locks the image providing access to the pixels. @@ -57,7 +57,7 @@ namespace ImageProcessorCore /// /// /// The - IPixelAccessor Lock(); + PixelAccessor Lock(); } /// diff --git a/src/ImageProcessorCore/Image/IImageFrame.cs b/src/ImageProcessorCore/Image/IImageFrame.cs index ad5e346943..5919b7e1e8 100644 --- a/src/ImageProcessorCore/Image/IImageFrame.cs +++ b/src/ImageProcessorCore/Image/IImageFrame.cs @@ -8,11 +8,11 @@ namespace ImageProcessorCore /// /// Represents a single frame in a animation. /// - /// The pixel format. - /// The packed format. long, float. - public interface IImageFrame : IImageBase - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public interface IImageFrame : IImageBase + where TColor : IPackedVector + where TPacked : struct { } } diff --git a/src/ImageProcessorCore/Image/IImageProcessor.cs b/src/ImageProcessorCore/Image/IImageProcessor.cs index fb325e0013..cf9f2c15d0 100644 --- a/src/ImageProcessorCore/Image/IImageProcessor.cs +++ b/src/ImageProcessorCore/Image/IImageProcessor.cs @@ -17,11 +17,11 @@ namespace ImageProcessorCore.Processors /// /// Encapsulates methods to alter the pixels of an image. /// - /// The pixel format. - /// The packed format. long, float. - public interface IImageProcessor - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public interface IImageProcessor + where TColor : IPackedVector + where TPacked : struct { /// /// Event fires when each row of the source image has been processed. @@ -44,7 +44,7 @@ namespace ImageProcessorCore.Processors bool Compand { get; set; } /// - /// Applies the process to the specified portion of the specified . + /// Applies the process to the specified portion of the specified . /// /// Target image to apply the process to. /// The source image. Cannot be null. @@ -61,10 +61,10 @@ namespace ImageProcessorCore.Processors /// /// doesnt fit the dimension of the image. /// - void Apply(ImageBase target, ImageBase source, Rectangle sourceRectangle); + void Apply(ImageBase target, ImageBase source, Rectangle sourceRectangle); /// - /// Applies the process to the specified portion of the specified at the specified + /// Applies the process to the specified portion of the specified at the specified /// location and with the specified size. /// /// Target image to apply the process to. @@ -82,6 +82,6 @@ namespace ImageProcessorCore.Processors /// The method keeps the source image unchanged and returns the /// the result of image process as new image. /// - void Apply(ImageBase target, ImageBase source, int width, int height, Rectangle targetRectangle, Rectangle sourceRectangle); + void Apply(ImageBase target, ImageBase source, int width, int height, Rectangle targetRectangle, Rectangle sourceRectangle); } } diff --git a/src/ImageProcessorCore/Image/Image.cs b/src/ImageProcessorCore/Image/Image.cs index 3c1e788726..960e5e26c2 100644 --- a/src/ImageProcessorCore/Image/Image.cs +++ b/src/ImageProcessorCore/Image/Image.cs @@ -18,12 +18,12 @@ namespace ImageProcessorCore /// /// Encapsulates an image, which consists of the pixel data for a graphics image and its attributes. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. [DebuggerDisplay("Image: {Width}x{Height}")] - public class Image : ImageBase - where T : IPackedVector - where TP : struct + public class Image : ImageBase + where TColor : IPackedVector + where TPacked : struct { /// /// The default horizontal resolution value (dots per inch) in x direction. @@ -38,7 +38,7 @@ namespace ImageProcessorCore public const double DefaultVerticalResolution = 96; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// public Image() { @@ -46,7 +46,7 @@ namespace ImageProcessorCore } /// - /// 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. @@ -58,12 +58,12 @@ namespace ImageProcessorCore } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// The stream containing image information. /// - /// Thrown if the is null. + /// Thrown if the is null. public Image(Stream stream) { Guard.NotNull(stream, nameof(stream)); @@ -71,19 +71,19 @@ namespace ImageProcessorCore } /// - /// 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) + /// is null. + 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)); } } @@ -169,7 +169,7 @@ namespace ImageProcessorCore /// 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. @@ -187,18 +187,12 @@ namespace ImageProcessorCore /// public ExifProfile ExifProfile { get; set; } - /// - public override IPixelAccessor Lock() - { - return Bootstrapper.Instance.GetPixelAccessor(this); - } - /// /// Saves the image to the given stream using the currently loaded image format. /// /// The stream to save the image to. - /// Thrown if the stream is null. - public Image Save(Stream stream) + /// Thrown if the stream is null. + public Image Save(Stream stream) { Guard.NotNull(stream, nameof(stream)); this.CurrentImageFormat.Encoder.Encode(this, stream); @@ -210,8 +204,8 @@ namespace ImageProcessorCore /// /// The stream to save the image to. /// The format to save the image as. - /// Thrown if the stream is null. - public Image Save(Stream stream, IImageFormat format) + /// Thrown if the stream is null. + public Image Save(Stream stream, IImageFormat format) { Guard.NotNull(stream, nameof(stream)); format.Encoder.Encode(this, stream); @@ -223,8 +217,8 @@ namespace ImageProcessorCore /// /// The stream to save the image to. /// The encoder to save the image with. - /// Thrown if the stream is null. - public Image Save(Stream stream, IImageEncoder encoder) + /// Thrown if the stream is null. + public Image Save(Stream stream, IImageEncoder encoder) { Guard.NotNull(stream, nameof(stream)); encoder.Encode(this, stream); @@ -247,12 +241,12 @@ namespace ImageProcessorCore } /// - /// 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); diff --git a/src/ImageProcessorCore/Image/ImageBase.cs b/src/ImageProcessorCore/Image/ImageBase.cs index 095f9c3626..9f4b36323e 100644 --- a/src/ImageProcessorCore/Image/ImageBase.cs +++ b/src/ImageProcessorCore/Image/ImageBase.cs @@ -3,6 +3,8 @@ // Licensed under the Apache License, Version 2.0. // +using System.Runtime.CompilerServices; + namespace ImageProcessorCore { using System; @@ -10,24 +12,29 @@ namespace ImageProcessorCore /// /// The base class of all images. Encapsulates the basic properties and methods required to manipulate - /// images in different pixel formats. + /// images in differenTColor pixel formats. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. [DebuggerDisplay("Image: {Width}x{Height}")] - public abstract class ImageBase : IImageBase - where T : IPackedVector - where TP : struct + public abstract unsafe class ImageBase : IImageBase + where TColor : IPackedVector + where TPacked : struct { /// - /// Initializes a new instance of the class. + /// The image pixels + /// + private TColor[] pixelBuffer; + + /// + /// 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. @@ -41,19 +48,19 @@ namespace ImageProcessorCore this.Width = width; this.Height = height; - this.Pixels = new T[width * height]; + this.pixelBuffer = new TColor[width * height]; } /// - /// 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."); @@ -62,8 +69,8 @@ namespace ImageProcessorCore this.CopyProperties(other); // Copy the pixels. - this.Pixels = new T[this.Width * this.Height]; - Array.Copy(other.Pixels, this.Pixels, other.Pixels.Length); + this.pixelBuffer = new TColor[this.Width * this.Height]; + Unsafe.Copy(Unsafe.AsPointer(ref this.pixelBuffer), ref other.pixelBuffer); } /// @@ -73,7 +80,7 @@ namespace ImageProcessorCore public int MaxHeight { get; set; } = int.MaxValue; /// - public T[] Pixels { get; private set; } + public TColor[] Pixels => this.pixelBuffer; /// public int Width { get; private set; } @@ -94,7 +101,7 @@ namespace ImageProcessorCore public int FrameDelay { get; set; } /// - public void SetPixels(int width, int height, T[] pixels) + public void SetPixels(int width, int height, TColor[] pixels) { if (width <= 0) { @@ -113,11 +120,11 @@ namespace ImageProcessorCore this.Width = width; this.Height = height; - this.Pixels = pixels; + this.pixelBuffer = pixels; } /// - public void ClonePixels(int width, int height, T[] pixels) + public void ClonePixels(int width, int height, TColor[] pixels) { if (width <= 0) { @@ -138,20 +145,23 @@ namespace ImageProcessorCore this.Height = height; // Copy the pixels. - this.Pixels = new T[pixels.Length]; - Array.Copy(pixels, this.Pixels, pixels.Length); + this.pixelBuffer = new TColor[pixels.Length]; + Unsafe.Copy(Unsafe.AsPointer(ref this.pixelBuffer), ref pixels); } /// - public abstract IPixelAccessor Lock(); + public PixelAccessor Lock() + { + 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/ImageProcessorCore/Image/ImageExtensions.cs b/src/ImageProcessorCore/Image/ImageExtensions.cs index c3aaf2f682..476c2a48e9 100644 --- a/src/ImageProcessorCore/Image/ImageExtensions.cs +++ b/src/ImageProcessorCore/Image/ImageExtensions.cs @@ -12,80 +12,80 @@ namespace ImageProcessorCore using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Saves the image to the given stream with the bmp format. /// - /// The pixel format. - /// The packed format. long, float. + /// 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. - public static void SaveAsBmp(this Image source, Stream stream) - where T : IPackedVector - where TP : struct + /// Thrown if the stream is null. + public static void SaveAsBmp(this Image source, Stream stream) + where TColor : IPackedVector + where TPacked : struct => new BmpEncoder().Encode(source, stream); /// /// Saves the image to the given stream with the png format. /// - /// The pixel format. - /// The packed format. long, float. + /// 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. /// Anything equal to 256 and below will cause the encoder to save the image in an indexed format. /// - /// Thrown if the stream is null. - public static void SaveAsPng(this Image source, Stream stream, int quality = int.MaxValue) - where T : IPackedVector - where TP : struct + /// Thrown if the stream is null. + public static void SaveAsPng(this Image source, Stream stream, int quality = int.MaxValue) + where TColor : IPackedVector + where TPacked : struct => new PngEncoder { Quality = quality }.Encode(source, stream); /// /// Saves the image to the given stream with the jpeg format. /// - /// The pixel format. - /// The packed format. long, float. + /// 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. - public static void SaveAsJpeg(this Image source, Stream stream, int quality = 75) - where T : IPackedVector - where TP : struct + /// Thrown if the stream is null. + public static void SaveAsJpeg(this Image source, Stream stream, int quality = 75) + where TColor : IPackedVector + where TPacked : struct => new JpegEncoder { Quality = quality }.Encode(source, stream); /// /// Saves the image to the given stream with the gif format. /// - /// The pixel format. - /// The packed format. long, float. + /// 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. - internal static void SaveAsGif(this Image source, Stream stream, int quality = 256) - where T : IPackedVector - where TP : struct + /// Thrown if the stream is null. + internal static void SaveAsGif(this Image source, Stream stream, int quality = 256) + where TColor : IPackedVector + where TPacked : struct => new GifEncoder { Quality = quality }.Encode(source, stream); /// /// Applies the collection of processors to the image. /// This method does not resize the target image. /// - /// The pixel format. - /// The packed format. long, float. + /// 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, IImageProcessor processor) - where T : IPackedVector - where TP : struct + /// The . + internal static Image Process(this Image source, IImageProcessor processor) + where TColor : IPackedVector + where TPacked : struct { return Process(source, source.Bounds, processor); } @@ -94,17 +94,17 @@ namespace ImageProcessorCore /// Applies the collection of processors to the image. /// This method does not resize the target image. /// - /// The pixel format. - /// The packed format. long, float. + /// 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, IImageProcessor processor) - where T : IPackedVector - where TP : struct + /// The . + internal static Image Process(this Image source, Rectangle sourceRectangle, IImageProcessor processor) + where TColor : IPackedVector + where TPacked : struct { return PerformAction(source, true, (sourceImage, targetImage) => processor.Apply(targetImage, sourceImage, sourceRectangle)); } @@ -115,16 +115,16 @@ namespace ImageProcessorCore /// This method is not chainable. /// /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The source image. Cannot be null. /// The target image width. /// The target image height. /// The processor to apply to the image. - /// The . - internal static Image Process(this Image source, int width, int height, IImageSampler sampler) - where T : IPackedVector - where TP : struct + /// The . + internal static Image Process(this Image source, int width, int height, IImageSampler sampler) + where TColor : IPackedVector + where TPacked : struct { return Process(source, width, height, source.Bounds, default(Rectangle), sampler); } @@ -135,8 +135,8 @@ namespace ImageProcessorCore /// This method does will resize the target image if the source and target rectangles are different. /// /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The source image. Cannot be null. /// The target image width. /// The target image height. @@ -148,10 +148,10 @@ namespace ImageProcessorCore /// The image is scaled to fit the rectangle. /// /// The processor to apply to the image. - /// The . - internal static Image Process(this Image source, int width, int height, Rectangle sourceRectangle, Rectangle targetRectangle, IImageSampler sampler) - where T : IPackedVector - where TP : struct + /// The . + internal static Image Process(this Image source, int width, int height, Rectangle sourceRectangle, Rectangle targetRectangle, IImageSampler sampler) + where TColor : IPackedVector + where TPacked : struct { return PerformAction(source, false, (sourceImage, targetImage) => sampler.Apply(targetImage, sourceImage, width, height, targetRectangle, sourceRectangle)); } @@ -159,19 +159,19 @@ namespace ImageProcessorCore /// /// Performs the given action on the source image. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image to perform the action against. /// Whether to clone the image. /// The to perform against the image. - /// The . - private static Image PerformAction(Image source, bool clone, Action, ImageBase> action) - where T : IPackedVector - where TP : struct + /// The . + private static Image PerformAction(Image source, bool clone, Action, ImageBase> action) + where TColor : IPackedVector + where TPacked : struct { - Image transformedImage = clone - ? new Image(source) - : new Image(); + Image transformedImage = clone + ? new Image(source) + : new Image(); // Several properties still require copying if (!clone) @@ -181,10 +181,10 @@ namespace ImageProcessorCore for (int i = 0; i < source.Frames.Count; i++) { - ImageFrame sourceFrame = source.Frames[i]; - ImageFrame tranformedFrame = clone - ? new ImageFrame(sourceFrame) - : new ImageFrame { FrameDelay = sourceFrame.FrameDelay }; + ImageFrame sourceFrame = source.Frames[i]; + ImageFrame tranformedFrame = clone + ? new ImageFrame(sourceFrame) + : new ImageFrame { FrameDelay = sourceFrame.FrameDelay }; action(sourceFrame, tranformedFrame); diff --git a/src/ImageProcessorCore/Image/ImageFrame.cs b/src/ImageProcessorCore/Image/ImageFrame.cs index 9b83029d28..44d0e07dab 100644 --- a/src/ImageProcessorCore/Image/ImageFrame.cs +++ b/src/ImageProcessorCore/Image/ImageFrame.cs @@ -8,34 +8,28 @@ namespace ImageProcessorCore /// /// Represents a single frame in a animation. /// - /// The pixel format. - /// The packed format. long, float. - public class ImageFrame : ImageBase - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class ImageFrame : ImageBase + where TColor : IPackedVector + where TPacked : struct { /// - /// 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 frame to create the frame from. /// - public ImageFrame(ImageFrame frame) + public ImageFrame(ImageFrame frame) : base(frame) { } - - /// - public override IPixelAccessor Lock() - { - return Bootstrapper.Instance.GetPixelAccessor(this); - } } } diff --git a/src/ImageProcessorCore/Image/PixelAccessor.cs b/src/ImageProcessorCore/Image/PixelAccessor.cs new file mode 100644 index 0000000000..833a4c6789 --- /dev/null +++ b/src/ImageProcessorCore/Image/PixelAccessor.cs @@ -0,0 +1,140 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageProcessorCore +{ + using System; + using System.Runtime.CompilerServices; + using System.Runtime.InteropServices; + + /// + /// Encapsulates properties to provides per-pixel access to an images pixels. + /// + /// The pixel format. + /// The packed format. uint, long, float. + public sealed unsafe class PixelAccessor : IDisposable + where TColor : IPackedVector + where TPacked : struct + { + /// + /// The pointer to the pixel buffer. + /// + private IntPtr dataPointer; + + /// + /// The position of the first pixel in the bitmap. + /// + private byte* pixelsBase; + + /// + /// Provides a way to access the pixels from unmanaged memory. + /// + private GCHandle pixelsHandle; + + /// + /// A value indicating whether this instance of the given entity has been disposed. + /// + /// if this instance has been disposed; otherwise, . + /// + /// If the entity is disposed, it must not be disposed a second time. The isDisposed field is set the first time the entity + /// is disposed. If the isDisposed field is true, then the Dispose() method will not dispose again. This help not to prolong the entity's + /// life in the Garbage Collector. + /// + private bool isDisposed; + + /// + /// Initializes a new instance of the class. + /// + /// The image to provide pixel access for. + public PixelAccessor(ImageBase image) + { + Guard.NotNull(image, nameof(image)); + Guard.MustBeGreaterThan(image.Width, 0, "image width"); + Guard.MustBeGreaterThan(image.Height, 0, "image height"); + + this.Width = image.Width; + this.Height = image.Height; + this.pixelsHandle = GCHandle.Alloc(image.Pixels, GCHandleType.Pinned); + this.dataPointer = this.pixelsHandle.AddrOfPinnedObject(); + this.pixelsBase = (byte*)this.dataPointer.ToPointer(); + this.PixelSize = Unsafe.SizeOf(); + this.RowStride = this.Width * this.PixelSize; + } + + /// + /// Finalizes an instance of the class. + /// + ~PixelAccessor() + { + this.Dispose(); + } + + /// + /// Gets the pointer to the pixel buffer. + /// + public IntPtr DataPointer => this.dataPointer; + + /// + /// Gets the width of one row in the number of bytes. + /// + public int PixelSize { get; } + + /// + /// Gets the width of one row in the number of bytes. + /// + public int RowStride { get; } + + /// + /// Gets the width of the image. + /// + public int Width { get; } + + /// + /// Gets the height of the image. + /// + public int Height { get; } + + /// + /// Gets or sets the pixel at the specified position. + /// + /// The x-coordinate of the pixel. Must be greater than zero and smaller than the width of the pixel. + /// The y-coordinate of the pixel. Must be greater than zero and smaller than the width of the pixel. + /// The at the specified position. + public TColor this[int x, int y] + { + get { return Unsafe.Read(pixelsBase + ((y * this.RowStride) + (x * this.PixelSize))); } + set { Unsafe.Write(pixelsBase + ((y * this.RowStride) + (x * this.PixelSize)), value); } + } + + /// + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + /// + public void Dispose() + { + if (this.isDisposed) + { + return; + } + + if (this.pixelsHandle.IsAllocated) + { + this.pixelsHandle.Free(); + } + + this.dataPointer = IntPtr.Zero; + this.pixelsBase = null; + + // Note disposing is done. + this.isDisposed = true; + + // This object will be cleaned up by the Dispose method. + // Therefore, you should call GC.SuppressFinalize to + // take this object off the finalization queue + // and prevent finalization code for this object + // from executing a second time. + GC.SuppressFinalize(this); + } + } +} \ No newline at end of file diff --git a/src/ImageProcessorCore/ImageProcessor.cs b/src/ImageProcessorCore/ImageProcessor.cs index 6d6796746d..2ed0e56b2c 100644 --- a/src/ImageProcessorCore/ImageProcessor.cs +++ b/src/ImageProcessorCore/ImageProcessor.cs @@ -12,9 +12,9 @@ namespace ImageProcessorCore.Processors /// /// Allows the application of processors to images. /// - public abstract class ImageProcessor : IImageProcessor - where T : IPackedVector - where TP : struct + public abstract class ImageProcessor : IImageProcessor + where TColor : IPackedVector + where TPacked : struct { /// public event ProgressEventHandler OnProgress; @@ -36,7 +36,7 @@ namespace ImageProcessorCore.Processors public virtual bool Compand { get; set; } = false; /// - public void Apply(ImageBase target, ImageBase source, Rectangle sourceRectangle) + public void Apply(ImageBase target, ImageBase source, Rectangle sourceRectangle) { try { @@ -57,11 +57,11 @@ namespace ImageProcessorCore.Processors } /// - public void Apply(ImageBase target, ImageBase source, int width, int height, Rectangle targetRectangle = default(Rectangle), Rectangle sourceRectangle = default(Rectangle)) + public void Apply(ImageBase target, ImageBase source, int width, int height, Rectangle targetRectangle = default(Rectangle), Rectangle sourceRectangle = default(Rectangle)) { try { - T[] pixels = new T[width * height]; + TColor[] pixels = new TColor[width * height]; target.SetPixels(width, height, pixels); // Ensure we always have bounds. @@ -93,8 +93,8 @@ namespace ImageProcessorCore.Processors /// /// This method is called before the process is applied to prepare the processor. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// Target image to apply the process to. /// The source image. Cannot be null. /// @@ -104,12 +104,12 @@ namespace ImageProcessorCore.Processors /// /// The structure that specifies the portion of the image object to draw. /// - protected virtual void OnApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) + protected virtual void OnApply(ImageBase target, ImageBase source, Rectangle targetRectangle, 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. /// /// Target image to apply the process to. @@ -127,7 +127,7 @@ namespace ImageProcessorCore.Processors /// The method keeps the source image unchanged and returns the /// the result of image process as new image. /// - protected abstract void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY); + protected abstract void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY); /// /// This method is called after the process is applied to prepare the processor. @@ -141,7 +141,7 @@ namespace ImageProcessorCore.Processors /// /// The structure that specifies the portion of the image object to draw. /// - protected virtual void AfterApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) + protected virtual void AfterApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) { } diff --git a/src/ImageProcessorCore/PixelAccessor/ColorPixelAccessor.cs b/src/ImageProcessorCore/PixelAccessor/ColorPixelAccessor.cs deleted file mode 100644 index 6d0812a2a4..0000000000 --- a/src/ImageProcessorCore/PixelAccessor/ColorPixelAccessor.cs +++ /dev/null @@ -1,155 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageProcessorCore -{ - using System; - using System.Runtime.InteropServices; - - /// - /// Provides per-pixel access to an images pixels. - /// - /// - /// The image data is always stored in format, where the red, green, blue, and - /// alpha values are 8 bit unsigned bytes. - /// - public sealed unsafe class ColorPixelAccessor : IPixelAccessor - { - /// - /// The position of the first pixel in the bitmap. - /// - private Color* pixelsBase; - - /// - /// Provides a way to access the pixels from unmanaged memory. - /// - private GCHandle pixelsHandle; - - /// - /// A value indicating whether this instance of the given entity has been disposed. - /// - /// if this instance has been disposed; otherwise, . - /// - /// If the entity is disposed, it must not be disposed a second - /// time. The isDisposed field is set the first time the entity - /// is disposed. If the isDisposed field is true, then the Dispose() - /// method will not dispose again. This help not to prolong the entity's - /// life in the Garbage Collector. - /// - private bool isDisposed; - - /// - /// Initializes a new instance of the class. - /// - /// - /// The image to provide pixel access for. - /// - public ColorPixelAccessor(IImageBase image) - { - Guard.NotNull(image, nameof(image)); - Guard.MustBeGreaterThan(image.Width, 0, "image width"); - Guard.MustBeGreaterThan(image.Height, 0, "image height"); - - this.Width = image.Width; - this.Height = image.Height; - - this.pixelsHandle = GCHandle.Alloc(((ImageBase)image).Pixels, GCHandleType.Pinned); - this.pixelsBase = (Color*)this.pixelsHandle.AddrOfPinnedObject().ToPointer(); - } - - /// - /// Finalizes an instance of the class. - /// - ~ColorPixelAccessor() - { - this.Dispose(); - } - - /// - /// Gets the width of the image. - /// - public int Width { get; } - - /// - /// Gets the height of the image. - /// - public int Height { get; } - - /// - /// Gets or sets the color of a pixel at the specified position. - /// - /// - /// The x-coordinate of the pixel. Must be greater - /// than zero and smaller than the width of the pixel. - /// - /// - /// The y-coordinate of the pixel. Must be greater - /// than zero and smaller than the width of the pixel. - /// - /// The at the specified position. - public Color this[int x, int y] - { - get - { -#if DEBUG - if ((x < 0) || (x >= this.Width)) - { - throw new ArgumentOutOfRangeException(nameof(x), "Value cannot be less than zero or greater than the bitmap width."); - } - - if ((y < 0) || (y >= this.Height)) - { - throw new ArgumentOutOfRangeException(nameof(y), "Value cannot be less than zero or greater than the bitmap height."); - } -#endif - return *(this.pixelsBase + ((y * this.Width) + x)); - } - - set - { -#if DEBUG - if ((x < 0) || (x >= this.Width)) - { - throw new ArgumentOutOfRangeException(nameof(x), "Value cannot be less than zero or greater than the bitmap width."); - } - - if ((y < 0) || (y >= this.Height)) - { - throw new ArgumentOutOfRangeException(nameof(y), "Value cannot be less than zero or greater than the bitmap height."); - } -#endif - *(this.pixelsBase + ((y * this.Width) + x)) = value; - } - } - - /// - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - /// - public void Dispose() - { - if (this.isDisposed) - { - return; - } - - if (this.pixelsHandle.IsAllocated) - { - this.pixelsHandle.Free(); - } - - this.pixelsBase = null; - - // Note disposing is done. - this.isDisposed = true; - - // This object will be cleaned up by the Dispose method. - // Therefore, you should call GC.SuppressFinalize to - // take this object off the finalization queue - // and prevent finalization code for this object - // from executing a second time. - GC.SuppressFinalize(this); - } - } -} diff --git a/src/ImageProcessorCore/PixelAccessor/IPixelAccessor.cs b/src/ImageProcessorCore/PixelAccessor/IPixelAccessor.cs deleted file mode 100644 index dcc1b5b681..0000000000 --- a/src/ImageProcessorCore/PixelAccessor/IPixelAccessor.cs +++ /dev/null @@ -1,53 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageProcessorCore -{ - using System; - - /// - /// Encapsulates properties to provides per-pixel access to an images pixels. - /// - /// The pixel format. - /// The packed format. long, float. - public interface IPixelAccessor : IPixelAccessor - where T : IPackedVector - where TP : struct - { - /// - /// Gets or sets the pixel at the specified position. - /// - /// - /// The x-coordinate of the pixel. Must be greater - /// than zero and smaller than the width of the pixel. - /// - /// - /// The y-coordinate of the pixel. Must be greater - /// than zero and smaller than the width of the pixel. - /// - /// The at the specified position. - T this[int x, int y] - { - get; - set; - } - } - - /// - /// Encapsulates properties to provides per-pixel access to an images pixels. - /// - public interface IPixelAccessor : IDisposable - { - /// - /// Gets the width of the image in pixels. - /// - int Width { get; } - - /// - /// Gets the height of the image in pixels. - /// - int Height { get; } - } -} diff --git a/src/ImageProcessorCore/Profiles/Exif/ExifProfile.cs b/src/ImageProcessorCore/Profiles/Exif/ExifProfile.cs index 86b90d76f9..638d721a7d 100644 --- a/src/ImageProcessorCore/Profiles/Exif/ExifProfile.cs +++ b/src/ImageProcessorCore/Profiles/Exif/ExifProfile.cs @@ -63,7 +63,7 @@ namespace ImageProcessorCore /// by making a copy from another EXIF profile. /// /// The other EXIF profile, where the clone should be made from. - /// is null. + /// is null. public ExifProfile(ExifProfile other) { Guard.NotNull(other, nameof(other)); @@ -115,11 +115,11 @@ namespace ImageProcessorCore /// /// Returns the thumbnail in the EXIF profile when available. /// - /// The pixel format. - /// The packed format. long, float. - public Image CreateThumbnail() - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public Image CreateThumbnail() + where TColor : IPackedVector + where TPacked : struct { this.InitializeValues(); @@ -135,7 +135,7 @@ namespace ImageProcessorCore using (MemoryStream memStream = new MemoryStream(this.data, this.thumbnailOffset, this.thumbnailLength)) { - return new Image(memStream); + return new Image(memStream); } } diff --git a/src/ImageProcessorCore/Profiles/Exif/ExifValue.cs b/src/ImageProcessorCore/Profiles/Exif/ExifValue.cs index 261317b3f8..3fd195b4ea 100644 --- a/src/ImageProcessorCore/Profiles/Exif/ExifValue.cs +++ b/src/ImageProcessorCore/Profiles/Exif/ExifValue.cs @@ -21,7 +21,7 @@ namespace ImageProcessorCore /// by making a copy from another exif value. /// /// The other exif value, where the clone should be made from. - /// is null. + /// is null. public ExifValue(ExifValue other) { Guard.NotNull(other, nameof(other)); diff --git a/src/ImageProcessorCore/Quantizers/IQuantizer.cs b/src/ImageProcessorCore/Quantizers/IQuantizer.cs index f6169b4299..af4733b118 100644 --- a/src/ImageProcessorCore/Quantizers/IQuantizer.cs +++ b/src/ImageProcessorCore/Quantizers/IQuantizer.cs @@ -8,21 +8,21 @@ namespace ImageProcessorCore.Quantizers /// /// Provides methods for allowing quantization of images pixels. /// - /// The pixel format. - /// The packed format. long, float. - public interface IQuantizer : IQuantizer - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public interface IQuantizer : IQuantizer + where TColor : IPackedVector + where TPacked : struct { /// - /// Quantize an image and return the resulting output pixels. + /// Quantize an image and return the resulting outpuTColor pixels. /// /// The image to quantize. /// The maximum number of colors to return. /// /// 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/ImageProcessorCore/Quantizers/Octree/OctreeQuantizer.cs b/src/ImageProcessorCore/Quantizers/Octree/OctreeQuantizer.cs index 3eb3f3d4b8..522e07151b 100644 --- a/src/ImageProcessorCore/Quantizers/Octree/OctreeQuantizer.cs +++ b/src/ImageProcessorCore/Quantizers/Octree/OctreeQuantizer.cs @@ -13,11 +13,11 @@ namespace ImageProcessorCore.Quantizers /// Encapsulates methods to calculate the colour palette if an image using an Octree pattern. /// /// - /// The pixel format. - /// The packed format. long, float. - public sealed class OctreeQuantizer : Quantizer - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public sealed class OctreeQuantizer : Quantizer + where TColor : IPackedVector + where TPacked : struct { /// /// Stores the tree @@ -30,7 +30,7 @@ namespace ImageProcessorCore.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, @@ -42,7 +42,7 @@ namespace ImageProcessorCore.Quantizers } /// - public override QuantizedImage Quantize(ImageBase image, int maxColors) + public override QuantizedImage Quantize(ImageBase image, int maxColors) { this.colors = maxColors.Clamp(1, 255); @@ -65,7 +65,7 @@ namespace ImageProcessorCore.Quantizers /// This function need only be overridden if your quantize algorithm needs two passes, /// such as an Octree quantizer. /// - protected override void InitialQuantizePixel(T pixel) + protected override void InitialQuantizePixel(TColor pixel) { // Add the color to the Octree this.octree.AddColor(pixel); @@ -80,7 +80,7 @@ namespace ImageProcessorCore.Quantizers /// /// The quantized value /// - protected override byte QuantizePixel(T pixel) + protected override byte QuantizePixel(TColor pixel) { // The color at [maxColors] is set to transparent byte paletteIndex = (byte)this.colors; @@ -100,15 +100,15 @@ namespace ImageProcessorCore.Quantizers /// /// The new color palette /// - protected override List GetPalette() + protected override List GetPalette() { // First off convert the Octree to maxColors colors - List palette = this.octree.Palletize(Math.Max(this.colors, 1)); + List palette = this.octree.Palletize(Math.Max(this.colors, 1)); int diff = this.colors - palette.Count; if (diff > 0) { - palette.AddRange(Enumerable.Repeat(default(T), diff)); + palette.AddRange(Enumerable.Repeat(default(TColor), diff)); } this.TransparentIndex = this.colors; @@ -161,7 +161,7 @@ namespace ImageProcessorCore.Quantizers /// /// Cache the previous color quantized /// - private TP previousColor; + private TPacked previousColor; /// /// Initializes a new instance of the class. @@ -175,7 +175,7 @@ namespace ImageProcessorCore.Quantizers this.Leaves = 0; this.reducibleNodes = new OctreeNode[9]; this.root = new OctreeNode(0, this.maxColorBits, this); - this.previousColor = default(TP); + this.previousColor = default(TPacked); this.previousNode = null; } @@ -195,9 +195,9 @@ namespace ImageProcessorCore.Quantizers /// /// The containing color information to add. /// - public void AddColor(T pixel) + public void AddColor(TColor pixel) { - TP packed = pixel.GetPackedValue(); + TPacked packed = pixel.GetPackedValue(); // Check if this request is for the same color as the last if (this.previousColor.Equals(packed)) { @@ -230,7 +230,7 @@ namespace ImageProcessorCore.Quantizers /// /// An with the palletized colors /// - public List Palletize(int colorCount) + public List Palletize(int colorCount) { while (this.Leaves > colorCount) { @@ -238,7 +238,7 @@ namespace ImageProcessorCore.Quantizers } // Now palletize the nodes - List palette = new List(this.Leaves); + List palette = new List(this.Leaves); int paletteIndex = 0; this.root.ConstructPalette(palette, ref paletteIndex); @@ -255,7 +255,7 @@ namespace ImageProcessorCore.Quantizers /// /// The index of the given structure. /// - public int GetPaletteIndex(T pixel) + public int GetPaletteIndex(TColor pixel) { return this.root.GetPaletteIndex(pixel, 0); } @@ -383,7 +383,7 @@ namespace ImageProcessorCore.Quantizers /// The number of significant color bits /// The level in the tree /// The tree to which this node belongs - public void AddColor(T pixel, int colorBits, int level, Octree octree) + public void AddColor(TColor pixel, int colorBits, int level, Octree octree) { // Update the color information if this is a leaf if (this.leaf) @@ -455,7 +455,7 @@ namespace ImageProcessorCore.Quantizers /// /// The current palette index /// - public void ConstructPalette(List palette, ref int index) + public void ConstructPalette(List palette, ref int index) { if (this.leaf) { @@ -467,7 +467,7 @@ namespace ImageProcessorCore.Quantizers byte b = (this.blue / this.pixelCount).ToByte(); // And set the color of the palette entry - T pixel = default(T); + TColor pixel = default(TColor); pixel.PackFromBytes(r, g, b, 255); palette.Add(pixel); } @@ -496,7 +496,7 @@ namespace ImageProcessorCore.Quantizers /// /// The representing the index of the pixel in the palette. /// - public int GetPaletteIndex(T pixel, int level) + public int GetPaletteIndex(TColor pixel, int level) { int index = this.paletteIndex; @@ -527,7 +527,7 @@ namespace ImageProcessorCore.Quantizers /// /// The pixel to add. /// - public void Increment(T pixel) + public void Increment(TColor pixel) { this.pixelCount++; byte[] components = pixel.ToBytes(); diff --git a/src/ImageProcessorCore/Quantizers/Octree/Quantizer.cs b/src/ImageProcessorCore/Quantizers/Octree/Quantizer.cs index 57ea9203ae..7bda2d4ab2 100644 --- a/src/ImageProcessorCore/Quantizers/Octree/Quantizer.cs +++ b/src/ImageProcessorCore/Quantizers/Octree/Quantizer.cs @@ -11,9 +11,9 @@ namespace ImageProcessorCore.Quantizers /// /// Encapsulates methods to calculate the color palette of an image. /// - public abstract class Quantizer : IQuantizer - where T : IPackedVector - where TP : struct + public abstract class Quantizer : IQuantizer + where TColor : IPackedVector + where TPacked : struct { /// /// Flag used to indicate whether a single pass or two passes are needed for quantization. @@ -21,7 +21,7 @@ namespace ImageProcessorCore.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 @@ -45,7 +45,7 @@ namespace ImageProcessorCore.Quantizers public byte Threshold { get; set; } /// - public virtual QuantizedImage Quantize(ImageBase image, int maxColors) + public virtual QuantizedImage Quantize(ImageBase image, int maxColors) { Guard.NotNull(image, nameof(image)); @@ -53,9 +53,9 @@ namespace ImageProcessorCore.Quantizers int height = image.Height; int width = image.Width; byte[] quantizedPixels = new byte[width * height]; - List palette; + List palette; - using (IPixelAccessor 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 @@ -71,7 +71,7 @@ namespace ImageProcessorCore.Quantizers this.SecondPass(pixels, quantizedPixels, width, height); } - return new QuantizedImage(width, height, palette.ToArray(), quantizedPixels, this.TransparentIndex); + return new QuantizedImage(width, height, palette.ToArray(), quantizedPixels, this.TransparentIndex); } /// @@ -80,7 +80,7 @@ namespace ImageProcessorCore.Quantizers /// The source data /// The width in pixels of the image. /// The height in pixels of the image. - protected virtual void FirstPass(IPixelAccessor 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++) @@ -98,10 +98,10 @@ namespace ImageProcessorCore.Quantizers /// Execute a second pass through the bitmap /// /// The source image. - /// The output pixel array + /// The outpuTColor pixel array /// The width in pixels of the image /// The height in pixels of the image - protected virtual void SecondPass(IPixelAccessor source, byte[] output, int width, int height) + protected virtual void SecondPass(PixelAccessor source, byte[] output, int width, int height) { Parallel.For( 0, @@ -111,7 +111,7 @@ namespace ImageProcessorCore.Quantizers { for (int x = 0; x < source.Width; x++) { - T sourcePixel = source[x, y]; + TColor sourcePixel = source[x, y]; output[(y * source.Width) + x] = this.QuantizePixel(sourcePixel); } }); @@ -125,7 +125,7 @@ namespace ImageProcessorCore.Quantizers /// This function need only be overridden if your quantize algorithm needs two passes, /// such as an Octree quantizer. /// - protected virtual void InitialQuantizePixel(T pixel) + protected virtual void InitialQuantizePixel(TColor pixel) { } @@ -136,7 +136,7 @@ namespace ImageProcessorCore.Quantizers /// /// The quantized value /// - protected abstract byte QuantizePixel(T pixel); + protected abstract byte QuantizePixel(TColor pixel); /// /// Retrieve the palette for the quantized image @@ -144,6 +144,6 @@ namespace ImageProcessorCore.Quantizers /// /// The new color palette /// - protected abstract List GetPalette(); + protected abstract List GetPalette(); } } \ No newline at end of file diff --git a/src/ImageProcessorCore/Quantizers/Palette/PaletteQuantizer.cs b/src/ImageProcessorCore/Quantizers/Palette/PaletteQuantizer.cs index 99c782c4d1..a075705358 100644 --- a/src/ImageProcessorCore/Quantizers/Palette/PaletteQuantizer.cs +++ b/src/ImageProcessorCore/Quantizers/Palette/PaletteQuantizer.cs @@ -14,11 +14,11 @@ namespace ImageProcessorCore.Quantizers /// Encapsulates methods to create a quantized image based upon the given palette. /// /// - /// The pixel format. - /// The packed format. long, float. - public class PaletteQuantizer : Quantizer - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class PaletteQuantizer : Quantizer + where TColor : IPackedVector + where TPacked : struct { /// /// A lookup table for colors @@ -28,25 +28,25 @@ namespace ImageProcessorCore.Quantizers /// /// List of all colors in the palette /// - private T[] colors; + 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 /// in the CSS Color Module Level 4. /// - public PaletteQuantizer(T[] palette = null) + public PaletteQuantizer(TColor[] palette = null) : base(true) { if (palette == null) { Color[] constants = ColorConstants.WebSafeColors; - List safe = new List { default(T) }; + List safe = new List { default(TColor) }; foreach (Color c in constants) { - T packed = default(T); + TColor packed = default(TColor); packed.PackFromVector4(c.ToVector4()); safe.Add(packed); } @@ -60,14 +60,14 @@ namespace ImageProcessorCore.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, 256)); return base.Quantize(image, maxColors); } /// - protected override byte QuantizePixel(T pixel) + protected override byte QuantizePixel(TColor pixel) { byte colorIndex = 0; string colorHash = pixel.ToString(); @@ -137,7 +137,7 @@ namespace ImageProcessorCore.Quantizers } /// - protected override List GetPalette() + protected override List GetPalette() { return this.colors.ToList(); } diff --git a/src/ImageProcessorCore/Quantizers/Quantize.cs b/src/ImageProcessorCore/Quantizers/Quantize.cs index 2db63a76b8..ea0102d592 100644 --- a/src/ImageProcessorCore/Quantizers/Quantize.cs +++ b/src/ImageProcessorCore/Quantizers/Quantize.cs @@ -8,36 +8,36 @@ using ImageProcessorCore.Quantizers; namespace ImageProcessorCore { /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Applies quantization to the image. /// - /// The pixel format. - /// The packed format. long, float. + /// 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 T : IPackedVector - where TP : struct + /// The . + public static Image Quantize(this Image source, Quantization mode = Quantization.Octree, int maxColors = 256) + where TColor : IPackedVector + where TPacked : struct { - 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; } @@ -47,17 +47,17 @@ namespace ImageProcessorCore /// /// Applies quantization to the image. /// - /// The pixel format. - /// The packed format. long, float. + /// 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 T : IPackedVector - where TP : struct + /// The . + public static Image Quantize(this Image source, IQuantizer quantizer, int maxColors) + where TColor : IPackedVector + where TPacked : struct { - 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/ImageProcessorCore/Quantizers/QuantizedImage.cs b/src/ImageProcessorCore/Quantizers/QuantizedImage.cs index 680f8b7ab0..f95483f37b 100644 --- a/src/ImageProcessorCore/Quantizers/QuantizedImage.cs +++ b/src/ImageProcessorCore/Quantizers/QuantizedImage.cs @@ -11,21 +11,21 @@ namespace ImageProcessorCore.Quantizers /// /// Represents a quantized image where the pixels indexed by a color palette. /// - /// The pixel format. - /// The packed format. long, float. - public class QuantizedImage - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class QuantizedImage + where TColor : IPackedVector + where TPacked : struct { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The image width. /// The image height. /// The color palette. /// The quantized pixels. /// The transparency index. - public QuantizedImage(int width, int height, T[] palette, byte[] pixels, int transparentIndex = -1) + public QuantizedImage(int width, int height, TColor[] palette, byte[] pixels, int transparentIndex = -1) { Guard.MustBeGreaterThan(width, 0, nameof(width)); Guard.MustBeGreaterThan(height, 0, nameof(height)); @@ -58,7 +58,7 @@ namespace ImageProcessorCore.Quantizers /// /// Gets the color palette of this . /// - public T[] Palette { get; } + public TColor[] Palette { get; } /// /// Gets the pixels of this . @@ -76,13 +76,13 @@ namespace ImageProcessorCore.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; - T[] pixels = new T[pixelCount]; + TColor[] pixels = new TColor[pixelCount]; Parallel.For( 0, @@ -90,7 +90,7 @@ namespace ImageProcessorCore.Quantizers Bootstrapper.Instance.ParallelOptions, i => { - T color = this.Palette[Math.Min(palletCount, this.Pixels[i])]; + TColor color = this.Palette[Math.Min(palletCount, this.Pixels[i])]; pixels[i] = color; }); diff --git a/src/ImageProcessorCore/Quantizers/Wu/WuQuantizer.cs b/src/ImageProcessorCore/Quantizers/Wu/WuQuantizer.cs index 952039ba45..a1f6b8f3cb 100644 --- a/src/ImageProcessorCore/Quantizers/Wu/WuQuantizer.cs +++ b/src/ImageProcessorCore/Quantizers/Wu/WuQuantizer.cs @@ -30,11 +30,11 @@ namespace ImageProcessorCore.Quantizers /// but more expensive versions. /// /// - /// The pixel format. - /// The packed format. long, float. - public sealed class WuQuantizer : IQuantizer - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public sealed class WuQuantizer : IQuantizer + where TColor : IPackedVector + where TPacked : struct { /// /// The epsilon for comparing floating point numbers. @@ -102,7 +102,7 @@ namespace ImageProcessorCore.Quantizers private readonly byte[] tag; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// public WuQuantizer() { @@ -119,7 +119,7 @@ namespace ImageProcessorCore.Quantizers public byte Threshold { get; set; } /// - public QuantizedImage Quantize(ImageBase image, int maxColors) + public QuantizedImage Quantize(ImageBase image, int maxColors) { Guard.NotNull(image, nameof(image)); @@ -127,7 +127,7 @@ namespace ImageProcessorCore.Quantizers this.Clear(); - using (IPixelAccessor imagePixels = image.Lock()) + using (PixelAccessor imagePixels = image.Lock()) { this.Build3DHistogram(imagePixels); this.Get3DMoments(); @@ -325,7 +325,7 @@ namespace ImageProcessorCore.Quantizers /// Builds a 3-D color histogram of counts, r/g/b, c^2. /// /// The pixel accessor. - private void Build3DHistogram(IPixelAccessor pixels) + private void Build3DHistogram(PixelAccessor pixels) { for (int y = 0; y < pixels.Height; y++) { @@ -723,9 +723,9 @@ namespace ImageProcessorCore.Quantizers /// The color count. /// The cube. /// The result. - private QuantizedImage GenerateResult(IPixelAccessor imagePixels, int colorCount, Box[] cube) + private QuantizedImage GenerateResult(PixelAccessor imagePixels, int colorCount, Box[] cube) { - List pallette = new List(); + List pallette = new List(); byte[] pixels = new byte[imagePixels.Width * imagePixels.Height]; int transparentIndex = -1; int width = imagePixels.Width; @@ -744,10 +744,10 @@ namespace ImageProcessorCore.Quantizers byte b = (byte)(Volume(cube[k], this.vmb) / weight); byte a = (byte)(Volume(cube[k], this.vma) / weight); - T color = default(T); + TColor color = default(TColor); color.PackFromBytes(r, g, b, a); - if (color.Equals(default(T))) + if (color.Equals(default(TColor))) { transparentIndex = k; } @@ -756,7 +756,7 @@ namespace ImageProcessorCore.Quantizers } else { - pallette.Add(default(T)); + pallette.Add(default(TColor)); transparentIndex = k; } } @@ -787,7 +787,7 @@ namespace ImageProcessorCore.Quantizers } }); - return new QuantizedImage(width, height, pallette.ToArray(), pixels, transparentIndex); + return new QuantizedImage(width, height, pallette.ToArray(), pixels, transparentIndex); } } } \ No newline at end of file diff --git a/src/ImageProcessorCore/Samplers/AutoOrient.cs b/src/ImageProcessorCore/Samplers/AutoOrient.cs index 62c7a55845..33f7902c26 100644 --- a/src/ImageProcessorCore/Samplers/AutoOrient.cs +++ b/src/ImageProcessorCore/Samplers/AutoOrient.cs @@ -8,20 +8,20 @@ namespace ImageProcessorCore using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Adjusts an image so that its orientation is suitable for viewing. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image to crop. /// The - public static Image AutoOrient(this Image source, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + public static Image AutoOrient(this Image source, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { Orientation orientation = GetExifOrientation(source); @@ -59,9 +59,9 @@ namespace ImageProcessorCore } } - private static Orientation GetExifOrientation(Image source) - where T : IPackedVector - where TP : struct + private static Orientation GetExifOrientation(Image source) + where TColor : IPackedVector + where TPacked : struct { if (source.ExifProfile == null) { diff --git a/src/ImageProcessorCore/Samplers/Crop.cs b/src/ImageProcessorCore/Samplers/Crop.cs index 84d343d6d6..01c7421a11 100644 --- a/src/ImageProcessorCore/Samplers/Crop.cs +++ b/src/ImageProcessorCore/Samplers/Crop.cs @@ -8,23 +8,23 @@ namespace ImageProcessorCore using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Crops an image to the given width and height. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image to resize. /// The target image width. /// The target image height. /// A delegate which is called as progress is made processing the image. - /// The - public static Image Crop(this Image source, int width, int height, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The + public static Image Crop(this Image source, int width, int height, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { return Crop(source, width, height, source.Bounds, progressHandler); } @@ -36,8 +36,8 @@ namespace ImageProcessorCore /// area within the source is resized performing a zoomed crop. /// /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image to crop. /// The target image width. /// The target image height. @@ -46,9 +46,9 @@ namespace ImageProcessorCore /// /// A delegate which is called as progress is made processing the image. /// The - public static Image Crop(this Image source, int width, int height, Rectangle sourceRectangle, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + public static Image Crop(this Image source, int width, int height, Rectangle sourceRectangle, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { Guard.MustBeGreaterThan(width, 0, nameof(width)); Guard.MustBeGreaterThan(height, 0, nameof(height)); @@ -60,7 +60,7 @@ namespace ImageProcessorCore source = source.Resize(sourceRectangle.Width, sourceRectangle.Height); } - CropProcessor processor = new CropProcessor(); + CropProcessor processor = new CropProcessor(); processor.OnProgress += progressHandler; try diff --git a/src/ImageProcessorCore/Samplers/EntropyCrop.cs b/src/ImageProcessorCore/Samplers/EntropyCrop.cs index cbc9eedee8..ba129dab4b 100644 --- a/src/ImageProcessorCore/Samplers/EntropyCrop.cs +++ b/src/ImageProcessorCore/Samplers/EntropyCrop.cs @@ -8,24 +8,24 @@ namespace ImageProcessorCore using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Crops an image to the area of greatest entropy. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image to crop. /// The threshold for entropic density. /// A delegate which is called as progress is made processing the image. /// The - public static Image EntropyCrop(this Image source, float threshold = .5f, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + public static Image EntropyCrop(this Image source, float threshold = .5f, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { - EntropyCropProcessor processor = new EntropyCropProcessor(threshold); + EntropyCropProcessor processor = new EntropyCropProcessor(threshold); processor.OnProgress += progressHandler; try diff --git a/src/ImageProcessorCore/Samplers/Flip.cs b/src/ImageProcessorCore/Samplers/Flip.cs index 9e0bd3121c..68a7e72298 100644 --- a/src/ImageProcessorCore/Samplers/Flip.cs +++ b/src/ImageProcessorCore/Samplers/Flip.cs @@ -8,24 +8,24 @@ namespace ImageProcessorCore using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Flips an image by the given instructions. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image to rotate, flip, or both. /// The to perform the flip. /// A delegate which is called as progress is made processing the image. /// The - public static Image Flip(this Image source, FlipType flipType, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + public static Image Flip(this Image source, FlipType flipType, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { - FlipProcessor processor = new FlipProcessor(flipType); + FlipProcessor processor = new FlipProcessor(flipType); processor.OnProgress += progressHandler; try diff --git a/src/ImageProcessorCore/Samplers/Options/ResizeHelper.cs b/src/ImageProcessorCore/Samplers/Options/ResizeHelper.cs index 96065f7e58..eab845cff7 100644 --- a/src/ImageProcessorCore/Samplers/Options/ResizeHelper.cs +++ b/src/ImageProcessorCore/Samplers/Options/ResizeHelper.cs @@ -17,15 +17,15 @@ namespace ImageProcessorCore /// /// Calculates the target location and bounds to perform the resize operation against. /// - /// The type of pixels contained within the image. + /// The type of pixels contained within the image. /// The source image. /// The resize options. /// /// The . /// - public static Rectangle CalculateTargetLocationAndBounds(ImageBase source, ResizeOptions options) - where T : IPackedVector - where TP : struct + public static Rectangle CalculateTargetLocationAndBounds(ImageBase source, ResizeOptions options) + where TColor : IPackedVector + where TPacked : struct { switch (options.Mode) { @@ -49,15 +49,15 @@ namespace ImageProcessorCore /// /// Calculates the target rectangle for crop mode. /// - /// The type of pixels contained within the image. + /// The type of pixels contained within the image. /// The source image. /// The resize options. /// /// The . /// - private static Rectangle CalculateCropRectangle(ImageBase source, ResizeOptions options) - where T : IPackedVector - where TP : struct + private static Rectangle CalculateCropRectangle(ImageBase source, ResizeOptions options) + where TColor : IPackedVector + where TPacked : struct { int width = options.Size.Width; int height = options.Size.Height; @@ -169,15 +169,15 @@ namespace ImageProcessorCore /// /// Calculates the target rectangle for pad mode. /// - /// The type of pixels contained within the image. + /// The type of pixels contained within the image. /// The source image. /// The resize options. /// /// The . /// - private static Rectangle CalculatePadRectangle(ImageBase source, ResizeOptions options) - where T : IPackedVector - where TP : struct + private static Rectangle CalculatePadRectangle(ImageBase source, ResizeOptions options) + where TColor : IPackedVector + where TPacked : struct { int width = options.Size.Width; int height = options.Size.Height; @@ -251,15 +251,15 @@ namespace ImageProcessorCore /// /// Calculates the target rectangle for box pad mode. /// - /// The type of pixels contained within the image. + /// The type of pixels contained within the image. /// The source image. /// The resize options. /// /// The . /// - private static Rectangle CalculateBoxPadRectangle(ImageBase source, ResizeOptions options) - where T : IPackedVector - where TP : struct + private static Rectangle CalculateBoxPadRectangle(ImageBase source, ResizeOptions options) + where TColor : IPackedVector + where TPacked : struct { int width = options.Size.Width; int height = options.Size.Height; @@ -339,15 +339,15 @@ namespace ImageProcessorCore /// /// Calculates the target rectangle for max mode. /// - /// The type of pixels contained within the image. + /// The type of pixels contained within the image. /// The source image. /// The resize options. /// /// The . /// - private static Rectangle CalculateMaxRectangle(ImageBase source, ResizeOptions options) - where T : IPackedVector - where TP : struct + private static Rectangle CalculateMaxRectangle(ImageBase source, ResizeOptions options) + where TColor : IPackedVector + where TPacked : struct { int width = options.Size.Width; int height = options.Size.Height; @@ -381,15 +381,15 @@ namespace ImageProcessorCore /// /// Calculates the target rectangle for min mode. /// - /// The type of pixels contained within the image. + /// The type of pixels contained within the image. /// The source image. /// The resize options. /// /// The . /// - private static Rectangle CalculateMinRectangle(ImageBase source, ResizeOptions options) - where T : IPackedVector - where TP : struct + private static Rectangle CalculateMinRectangle(ImageBase source, ResizeOptions options) + where TColor : IPackedVector + where TPacked : struct { int width = options.Size.Width; int height = options.Size.Height; diff --git a/src/ImageProcessorCore/Samplers/Pad.cs b/src/ImageProcessorCore/Samplers/Pad.cs index 6be9f654c4..6d932a306d 100644 --- a/src/ImageProcessorCore/Samplers/Pad.cs +++ b/src/ImageProcessorCore/Samplers/Pad.cs @@ -8,23 +8,23 @@ namespace ImageProcessorCore using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Evenly pads an image to fit the new dimensions. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The source image to pad. /// The new width. /// The new height. /// A delegate which is called as progress is made processing the image. - /// The . - public static Image Pad(this Image source, int width, int height, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + /// The . + public static Image Pad(this Image source, int width, int height, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { ResizeOptions options = new ResizeOptions { diff --git a/src/ImageProcessorCore/Samplers/Processors/CompandingResizeProcessor.cs b/src/ImageProcessorCore/Samplers/Processors/CompandingResizeProcessor.cs index 1790c4a9d6..acbd7f5f01 100644 --- a/src/ImageProcessorCore/Samplers/Processors/CompandingResizeProcessor.cs +++ b/src/ImageProcessorCore/Samplers/Processors/CompandingResizeProcessor.cs @@ -13,14 +13,14 @@ namespace ImageProcessorCore.Processors /// Provides methods that allow the resizing of images using various algorithms. /// This version will expand and compress the image to and from a linear color space during processing. /// - /// The pixel format. - /// The packed format. long, float. - public class CompandingResizeProcessor : ResamplingWeightedProcessor - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class CompandingResizeProcessor : ResamplingWeightedProcessor + where TColor : IPackedVector + where TPacked : struct { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// The sampler to perform the resize operation. @@ -34,7 +34,7 @@ namespace ImageProcessorCore.Processors public override bool Compand { get; set; } = true; /// - protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) + protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) { // Jump out, we'll deal with that later. if (source.Bounds == target.Bounds && sourceRectangle == targetRectangle) @@ -63,8 +63,8 @@ namespace ImageProcessorCore.Processors float widthFactor = sourceRectangle.Width / (float)targetRectangle.Width; float heightFactor = sourceRectangle.Height / (float)targetRectangle.Height; - using (IPixelAccessor sourcePixels = source.Lock()) - using (IPixelAccessor targetPixels = target.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock()) { Parallel.For( minY, @@ -93,10 +93,10 @@ namespace ImageProcessorCore.Processors // A 2-pass 1D algorithm appears to be faster than splitting a 1-pass 2D algorithm // First process the columns. Since we are not using multiple threads startY and endY // are the upper and lower bounds of the source rectangle. - Image firstPass = new Image(target.Width, source.Height); - using (IPixelAccessor sourcePixels = source.Lock()) - using (IPixelAccessor firstPassPixels = firstPass.Lock()) - using (IPixelAccessor targetPixels = target.Lock()) + Image firstPass = new Image(target.Width, source.Height); + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor firstPassPixels = firstPass.Lock()) + using (PixelAccessor targetPixels = target.Lock()) { minX = Math.Max(0, startX); maxX = Math.Min(width, endX); @@ -123,7 +123,7 @@ namespace ImageProcessorCore.Processors destination += sourcePixels[xw.Index, y].ToVector4().Expand() * xw.Value; } - T d = default(T); + TColor d = default(TColor); d.PackFromVector4(destination.Compress()); firstPassPixels[x, y] = d; } @@ -150,7 +150,7 @@ namespace ImageProcessorCore.Processors destination += firstPassPixels[x, yw.Index].ToVector4().Expand() * yw.Value; } - T d = default(T); + TColor d = default(TColor); d.PackFromVector4(destination.Compress()); targetPixels[x, y] = d; } diff --git a/src/ImageProcessorCore/Samplers/Processors/CropProcessor.cs b/src/ImageProcessorCore/Samplers/Processors/CropProcessor.cs index f18a68d322..573eb70420 100644 --- a/src/ImageProcessorCore/Samplers/Processors/CropProcessor.cs +++ b/src/ImageProcessorCore/Samplers/Processors/CropProcessor.cs @@ -10,22 +10,22 @@ namespace ImageProcessorCore.Processors /// /// Provides methods to allow the cropping of an image. /// - /// The pixel format. - /// The packed format. long, float. - public class CropProcessor : ImageSampler - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class CropProcessor : ImageSampler + where TColor : IPackedVector + where TPacked : struct { /// - protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) + protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) { int startX = targetRectangle.X; int endX = targetRectangle.Right; int sourceX = sourceRectangle.X; int sourceY = sourceRectangle.Y; - using (IPixelAccessor sourcePixels = source.Lock()) - using (IPixelAccessor targetPixels = target.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock()) { Parallel.For( startY, diff --git a/src/ImageProcessorCore/Samplers/Processors/EntropyCropProcessor.cs b/src/ImageProcessorCore/Samplers/Processors/EntropyCropProcessor.cs index 8d4ad68855..f20b7bce1d 100644 --- a/src/ImageProcessorCore/Samplers/Processors/EntropyCropProcessor.cs +++ b/src/ImageProcessorCore/Samplers/Processors/EntropyCropProcessor.cs @@ -12,11 +12,11 @@ namespace ImageProcessorCore.Processors /// Provides methods to allow the cropping of an image to preserve areas of highest /// entropy. /// - /// The pixel format. - /// The packed format. long, float. - public class EntropyCropProcessor : ImageSampler - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class EntropyCropProcessor : ImageSampler + where TColor : IPackedVector + where TPacked : struct { /// /// The rectangle for cropping @@ -24,7 +24,7 @@ namespace ImageProcessorCore.Processors private Rectangle cropRectangle; /// - /// 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. /// @@ -42,26 +42,26 @@ namespace ImageProcessorCore.Processors public float Value { get; } /// - protected override void OnApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) + protected override void OnApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) { - ImageBase temp = new Image(source.Width, source.Height); + ImageBase temp = new Image(source.Width, source.Height); // Detect the edges. - new SobelProcessor().Apply(temp, source, sourceRectangle); + new SobelProcessor().Apply(temp, source, sourceRectangle); // Apply threshold binarization filter. - new BinaryThresholdProcessor(.5f).Apply(temp, temp, sourceRectangle); + new BinaryThresholdProcessor(.5f).Apply(temp, temp, sourceRectangle); // Search for the first white pixels Rectangle rectangle = ImageMaths.GetFilteredBoundingRectangle(temp, 0); - // Reset the target pixel to the correct size. - target.SetPixels(rectangle.Width, rectangle.Height, new T[rectangle.Width * rectangle.Height]); + // Reset the targeTColor pixel to the correct size. + target.SetPixels(rectangle.Width, rectangle.Height, new TColor[rectangle.Width * rectangle.Height]); this.cropRectangle = rectangle; } /// - protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) + protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) { // Jump out, we'll deal with that later. if (source.Bounds == target.Bounds) @@ -77,8 +77,8 @@ namespace ImageProcessorCore.Processors int minY = Math.Max(targetY, startY); int maxY = Math.Min(targetBottom, endY); - using (IPixelAccessor sourcePixels = source.Lock()) - using (IPixelAccessor targetPixels = target.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock()) { Parallel.For( minY, @@ -97,7 +97,7 @@ namespace ImageProcessorCore.Processors } /// - protected override void AfterApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) + protected override void AfterApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) { // Copy the pixels over. if (source.Bounds == target.Bounds) diff --git a/src/ImageProcessorCore/Samplers/Processors/FlipProcessor.cs b/src/ImageProcessorCore/Samplers/Processors/FlipProcessor.cs index c4de4a121e..5efc72b492 100644 --- a/src/ImageProcessorCore/Samplers/Processors/FlipProcessor.cs +++ b/src/ImageProcessorCore/Samplers/Processors/FlipProcessor.cs @@ -11,14 +11,14 @@ namespace ImageProcessorCore.Processors /// /// Provides methods that allow the flipping of an image around its center point. /// - /// The pixel format. - /// The packed format. long, float. - public class FlipProcessor : ImageSampler - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class FlipProcessor : ImageSampler + where TColor : IPackedVector + where TPacked : struct { /// - /// 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 +32,7 @@ namespace ImageProcessorCore.Processors public FlipType FlipType { get; } /// - protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) + protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) { target.ClonePixels(target.Width, target.Height, source.Pixels); @@ -53,16 +53,16 @@ namespace ImageProcessorCore.Processors /// at half the height of the image. /// /// Target image to apply the process to. - private void FlipX(ImageBase target) + private void FlipX(ImageBase target) { int width = target.Width; int height = target.Height; int halfHeight = (int)Math.Ceiling(target.Height * .5F); - Image temp = new Image(width, height); + Image temp = new Image(width, height); temp.ClonePixels(width, height, target.Pixels); - using (IPixelAccessor targetPixels = target.Lock()) - using (IPixelAccessor tempPixels = temp.Lock()) + using (PixelAccessor targetPixels = target.Lock()) + using (PixelAccessor tempPixels = temp.Lock()) { Parallel.For( 0, @@ -87,16 +87,16 @@ namespace ImageProcessorCore.Processors /// at half of the width of the image. /// /// Target image to apply the process to. - private void FlipY(ImageBase target) + private void FlipY(ImageBase target) { int width = target.Width; int height = target.Height; int halfWidth = (int)Math.Ceiling(width * .5F); - Image temp = new Image(width, height); + Image temp = new Image(width, height); temp.ClonePixels(width, height, target.Pixels); - using (IPixelAccessor targetPixels = target.Lock()) - using (IPixelAccessor tempPixels = temp.Lock()) + using (PixelAccessor targetPixels = target.Lock()) + using (PixelAccessor tempPixels = temp.Lock()) { Parallel.For( 0, diff --git a/src/ImageProcessorCore/Samplers/Processors/IImageSampler.cs b/src/ImageProcessorCore/Samplers/Processors/IImageSampler.cs index 36fe5810fb..edf293b1f4 100644 --- a/src/ImageProcessorCore/Samplers/Processors/IImageSampler.cs +++ b/src/ImageProcessorCore/Samplers/Processors/IImageSampler.cs @@ -8,9 +8,9 @@ namespace ImageProcessorCore.Processors /// /// Acts as a marker for generic parameters that require an image sampler. /// - public interface IImageSampler : IImageProcessor - where T : IPackedVector - where TP : struct + public interface IImageSampler : IImageProcessor + where TColor : IPackedVector + where TPacked : struct { } } diff --git a/src/ImageProcessorCore/Samplers/Processors/ImageSampler.cs b/src/ImageProcessorCore/Samplers/Processors/ImageSampler.cs index 9dabc7ebab..c1d4d5c704 100644 --- a/src/ImageProcessorCore/Samplers/Processors/ImageSampler.cs +++ b/src/ImageProcessorCore/Samplers/Processors/ImageSampler.cs @@ -9,11 +9,11 @@ namespace ImageProcessorCore.Processors /// Applies sampling methods to an image. /// All processors requiring resampling or resizing should inherit from this. /// - /// The pixel format. - /// The packed format. long, float. - public abstract class ImageSampler : ImageProcessor, IImageSampler - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public abstract class ImageSampler : ImageProcessor, IImageSampler + where TColor : IPackedVector + where TPacked : struct { } } diff --git a/src/ImageProcessorCore/Samplers/Processors/Matrix3x2Processor.cs b/src/ImageProcessorCore/Samplers/Processors/Matrix3x2Processor.cs index 7d5f536289..86b086b29e 100644 --- a/src/ImageProcessorCore/Samplers/Processors/Matrix3x2Processor.cs +++ b/src/ImageProcessorCore/Samplers/Processors/Matrix3x2Processor.cs @@ -10,11 +10,11 @@ namespace ImageProcessorCore.Processors /// /// Provides methods to transform an image using a . /// - /// The pixel format. - /// The packed format. long, float. - public abstract class Matrix3x2Processor : ImageSampler - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public abstract class Matrix3x2Processor : ImageSampler + where TColor : IPackedVector + where TPacked : struct { /// /// Creates a new target to contain the results of the matrix transform. @@ -22,13 +22,13 @@ namespace ImageProcessorCore.Processors /// Target image to apply the process to. /// The source rectangle. /// The processing matrix. - protected static void CreateNewTarget(ImageBase target, Rectangle sourceRectangle, Matrix3x2 processMatrix) + protected static void CreateNewTarget(ImageBase target, Rectangle sourceRectangle, Matrix3x2 processMatrix) { Matrix3x2 sizeMatrix; if (Matrix3x2.Invert(processMatrix, out sizeMatrix)) { Rectangle rectangle = ImageMaths.GetBoundingRectangle(sourceRectangle, sizeMatrix); - target.SetPixels(rectangle.Width, rectangle.Height, new T[rectangle.Width * rectangle.Height]); + target.SetPixels(rectangle.Width, rectangle.Height, new TColor[rectangle.Width * rectangle.Height]); } } @@ -41,7 +41,7 @@ namespace ImageProcessorCore.Processors /// /// The . /// - protected static Matrix3x2 GetCenteredMatrix(ImageBase target, ImageBase source, Matrix3x2 matrix) + protected static Matrix3x2 GetCenteredMatrix(ImageBase target, ImageBase source, Matrix3x2 matrix) { Matrix3x2 translationToTargetCenter = Matrix3x2.CreateTranslation(-target.Width * .5F, -target.Height * .5F); Matrix3x2 translateToSourceCenter = Matrix3x2.CreateTranslation(source.Width * .5F, source.Height * .5F); diff --git a/src/ImageProcessorCore/Samplers/Processors/ResamplingWeightedProcessor.cs b/src/ImageProcessorCore/Samplers/Processors/ResamplingWeightedProcessor.cs index 70e9b16631..16f2ec2920 100644 --- a/src/ImageProcessorCore/Samplers/Processors/ResamplingWeightedProcessor.cs +++ b/src/ImageProcessorCore/Samplers/Processors/ResamplingWeightedProcessor.cs @@ -11,14 +11,14 @@ namespace ImageProcessorCore.Processors /// Provides methods that allow the resizing of images using various algorithms. /// Adapted from /// - /// The pixel format. - /// The packed format. long, float. - public abstract class ResamplingWeightedProcessor : ImageSampler - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public abstract class ResamplingWeightedProcessor : ImageSampler + where TColor : IPackedVector + where TPacked : struct { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// The sampler to perform the resize operation. @@ -46,7 +46,7 @@ namespace ImageProcessorCore.Processors protected Weights[] VerticalWeights { get; set; } /// - protected override void OnApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) + protected override void OnApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) { if (!(this.Sampler is NearestNeighborResampler)) { @@ -56,7 +56,7 @@ namespace ImageProcessorCore.Processors } /// - protected override void AfterApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) + protected override void AfterApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) { // Copy the pixels over. if (source.Bounds == target.Bounds && sourceRectangle == targetRectangle) diff --git a/src/ImageProcessorCore/Samplers/Processors/ResizeProcessor.cs b/src/ImageProcessorCore/Samplers/Processors/ResizeProcessor.cs index 408ca9e544..21a0a3b11e 100644 --- a/src/ImageProcessorCore/Samplers/Processors/ResizeProcessor.cs +++ b/src/ImageProcessorCore/Samplers/Processors/ResizeProcessor.cs @@ -13,16 +13,16 @@ namespace ImageProcessorCore.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. long, float. - public class ResizeProcessor : ResamplingWeightedProcessor - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class ResizeProcessor : ResamplingWeightedProcessor + where TColor : IPackedVector + where TPacked : struct { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// The sampler to perform the resize operation. @@ -33,7 +33,7 @@ namespace ImageProcessorCore.Processors } /// - protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) + protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) { // Jump out, we'll deal with that later. if (source.Bounds == target.Bounds && sourceRectangle == targetRectangle) @@ -62,8 +62,8 @@ namespace ImageProcessorCore.Processors float widthFactor = sourceRectangle.Width / (float)targetRectangle.Width; float heightFactor = sourceRectangle.Height / (float)targetRectangle.Height; - using (IPixelAccessor sourcePixels = source.Lock()) - using (IPixelAccessor targetPixels = target.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock()) { Parallel.For( minY, @@ -92,10 +92,10 @@ namespace ImageProcessorCore.Processors // A 2-pass 1D algorithm appears to be faster than splitting a 1-pass 2D algorithm // First process the columns. Since we are not using multiple threads startY and endY // are the upper and lower bounds of the source rectangle. - Image firstPass = new Image(target.Width, source.Height); - using (IPixelAccessor sourcePixels = source.Lock()) - using (IPixelAccessor firstPassPixels = firstPass.Lock()) - using (IPixelAccessor targetPixels = target.Lock()) + Image firstPass = new Image(target.Width, source.Height); + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor firstPassPixels = firstPass.Lock()) + using (PixelAccessor targetPixels = target.Lock()) { minX = Math.Max(0, startX); maxX = Math.Min(width, endX); @@ -122,7 +122,7 @@ namespace ImageProcessorCore.Processors destination += sourcePixels[xw.Index, y].ToVector4() * xw.Value; } - T d = default(T); + TColor d = default(TColor); d.PackFromVector4(destination); firstPassPixels[x, y] = d; } @@ -149,7 +149,7 @@ namespace ImageProcessorCore.Processors destination += firstPassPixels[x, yw.Index].ToVector4() * yw.Value; } - T d = default(T); + TColor d = default(TColor); d.PackFromVector4(destination); targetPixels[x, y] = d; } diff --git a/src/ImageProcessorCore/Samplers/Processors/RotateProcessor.cs b/src/ImageProcessorCore/Samplers/Processors/RotateProcessor.cs index 3425d6b8dd..df3eea635b 100644 --- a/src/ImageProcessorCore/Samplers/Processors/RotateProcessor.cs +++ b/src/ImageProcessorCore/Samplers/Processors/RotateProcessor.cs @@ -10,11 +10,11 @@ namespace ImageProcessorCore.Processors /// /// Provides methods that allow the rotating of images. /// - /// The pixel format. - /// The packed format. long, float. - public class RotateProcessor : Matrix3x2Processor - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class RotateProcessor : Matrix3x2Processor + where TColor : IPackedVector + where TPacked : struct { /// /// The tranform matrix to apply. @@ -32,7 +32,7 @@ namespace ImageProcessorCore.Processors public bool Expand { get; set; } = true; /// - protected override void OnApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) + protected override void OnApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) { if (Angle == 0 || Angle == 90 || Angle == 180 || Angle == 270) { @@ -47,7 +47,7 @@ namespace ImageProcessorCore.Processors } /// - protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) + protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) { if (OptimizedApply(target, source)) { @@ -58,8 +58,8 @@ namespace ImageProcessorCore.Processors int width = target.Width; Matrix3x2 matrix = GetCenteredMatrix(target, source, this.processMatrix); - using (IPixelAccessor sourcePixels = source.Lock()) - using (IPixelAccessor targetPixels = target.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock()) { Parallel.For( 0, @@ -87,7 +87,7 @@ namespace ImageProcessorCore.Processors /// The target image. /// The source image. /// - private bool OptimizedApply(ImageBase target, ImageBase source) + private bool OptimizedApply(ImageBase target, ImageBase source) { if (Angle == 0) { @@ -121,14 +121,14 @@ namespace ImageProcessorCore.Processors /// /// The target image. /// The source image. - private void Rotate270(ImageBase target, ImageBase source) + private void Rotate270(ImageBase target, ImageBase source) { int width = source.Width; int height = source.Height; - Image temp = new Image(height, width); + Image temp = new Image(height, width); - using (IPixelAccessor sourcePixels = source.Lock()) - using (IPixelAccessor tempPixels = temp.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor tempPixels = temp.Lock()) { Parallel.For( 0, @@ -156,13 +156,13 @@ namespace ImageProcessorCore.Processors /// /// The target image. /// The source image. - private void Rotate180(ImageBase target, ImageBase source) + private void Rotate180(ImageBase target, ImageBase source) { int width = source.Width; int height = source.Height; - using (IPixelAccessor sourcePixels = source.Lock()) - using (IPixelAccessor targetPixels = target.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock()) { Parallel.For( 0, @@ -187,14 +187,14 @@ namespace ImageProcessorCore.Processors /// /// The target image. /// The source image. - private void Rotate90(ImageBase target, ImageBase source) + private void Rotate90(ImageBase target, ImageBase source) { int width = source.Width; int height = source.Height; - Image temp = new Image(height, width); + Image temp = new Image(height, width); - using (IPixelAccessor sourcePixels = source.Lock()) - using (IPixelAccessor tempPixels = temp.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor tempPixels = temp.Lock()) { Parallel.For( 0, diff --git a/src/ImageProcessorCore/Samplers/Processors/SkewProcessor.cs b/src/ImageProcessorCore/Samplers/Processors/SkewProcessor.cs index 24285d67bc..44d1efd8fc 100644 --- a/src/ImageProcessorCore/Samplers/Processors/SkewProcessor.cs +++ b/src/ImageProcessorCore/Samplers/Processors/SkewProcessor.cs @@ -11,11 +11,11 @@ namespace ImageProcessorCore.Processors /// /// Provides methods that allow the skewing of images. /// - /// The pixel format. - /// The packed format. long, float. - public class SkewProcessor : Matrix3x2Processor - where T : IPackedVector - where TP : struct + /// The pixel format. + /// The packed format. uint, long, float. + public class SkewProcessor : Matrix3x2Processor + where TColor : IPackedVector + where TPacked : struct { /// /// The tranform matrix to apply. @@ -38,7 +38,7 @@ namespace ImageProcessorCore.Processors public bool Expand { get; set; } = true; /// - protected override void OnApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) + protected override void OnApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) { this.processMatrix = Point.CreateSkew(new Point(0, 0), -this.AngleX, -this.AngleY); if (this.Expand) @@ -48,14 +48,14 @@ namespace ImageProcessorCore.Processors } /// - protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) + protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) { int height = target.Height; int width = target.Width; Matrix3x2 matrix = GetCenteredMatrix(target, source, this.processMatrix); - using (IPixelAccessor sourcePixels = source.Lock()) - using (IPixelAccessor targetPixels = target.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock()) { Parallel.For( 0, diff --git a/src/ImageProcessorCore/Samplers/Resamplers/NearestNeighborResampler.cs b/src/ImageProcessorCore/Samplers/Resamplers/NearestNeighborResampler.cs index 58b6a9d584..bcd9a58b1c 100644 --- a/src/ImageProcessorCore/Samplers/Resamplers/NearestNeighborResampler.cs +++ b/src/ImageProcessorCore/Samplers/Resamplers/NearestNeighborResampler.cs @@ -7,7 +7,7 @@ namespace ImageProcessorCore { /// /// The function implements the nearest neighbour algorithm. This uses an unscaled filter - /// which will select the closest pixel to the new pixels position. + /// which will select the closesTColor pixel to the new pixels position. /// public class NearestNeighborResampler : IResampler { diff --git a/src/ImageProcessorCore/Samplers/Resize.cs b/src/ImageProcessorCore/Samplers/Resize.cs index 5fa2eff702..e2eb5775cb 100644 --- a/src/ImageProcessorCore/Samplers/Resize.cs +++ b/src/ImageProcessorCore/Samplers/Resize.cs @@ -8,23 +8,23 @@ namespace ImageProcessorCore using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Resizes an image in accordance with the given . /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image to resize. /// The resize options. /// A delegate which is called as progress is made processing the image. - /// 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, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + public static Image Resize(this Image source, ResizeOptions options, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { // Ensure size is populated across both dimensions. if (options.Size.Width == 0 && options.Size.Height > 0) @@ -45,17 +45,17 @@ namespace ImageProcessorCore /// /// Resizes an image to the given width and height. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image to resize. /// The target image width. /// The target image height. /// A delegate which is called as progress is made processing the image. - /// 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, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + public static Image Resize(this Image source, int width, int height, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { return Resize(source, width, height, new BicubicResampler(), false, progressHandler); } @@ -63,18 +63,18 @@ namespace ImageProcessorCore /// /// Resizes an image to the given width and height. /// - /// The pixel format. - /// The packed format. long, float. + /// 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. /// A delegate which is called as progress is made processing the image. - /// 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, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + public static Image Resize(this Image source, int width, int height, bool compand, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { return Resize(source, width, height, new BicubicResampler(), compand, progressHandler); } @@ -82,19 +82,19 @@ namespace ImageProcessorCore /// /// Resizes an image to the given width and height with the given sampler. /// - /// The pixel format. - /// The packed format. long, float. + /// 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. /// A delegate which is called as progress is made processing the image. - /// 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, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + public static Image Resize(this Image source, int width, int height, IResampler sampler, bool compand, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { return Resize(source, width, height, sampler, source.Bounds, new Rectangle(0, 0, width, height), compand, progressHandler); } @@ -103,8 +103,8 @@ namespace ImageProcessorCore /// Resizes an image to the given width and height with the given sampler and /// source rectangle. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image to resize. /// The target image width. /// The target image height. @@ -117,11 +117,11 @@ namespace ImageProcessorCore /// /// Whether to compress and expand the image color-space to gamma correct the image during processing. /// A delegate which is called as progress is made processing the image. - /// 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, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + public static Image Resize(this Image source, int width, int height, IResampler sampler, Rectangle sourceRectangle, Rectangle targetRectangle, bool compand = false, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { if (width == 0 && height > 0) { @@ -138,15 +138,15 @@ namespace ImageProcessorCore Guard.MustBeGreaterThan(width, 0, nameof(width)); Guard.MustBeGreaterThan(height, 0, nameof(height)); - ResamplingWeightedProcessor processor; + ResamplingWeightedProcessor processor; if (compand) { - processor = new CompandingResizeProcessor(sampler); + processor = new CompandingResizeProcessor(sampler); } else { - processor = new ResizeProcessor(sampler); + processor = new ResizeProcessor(sampler); } processor.OnProgress += progressHandler; diff --git a/src/ImageProcessorCore/Samplers/Rotate.cs b/src/ImageProcessorCore/Samplers/Rotate.cs index 21249bcc24..1774abaaf5 100644 --- a/src/ImageProcessorCore/Samplers/Rotate.cs +++ b/src/ImageProcessorCore/Samplers/Rotate.cs @@ -8,22 +8,22 @@ namespace ImageProcessorCore using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Rotates an image by the given angle in degrees, expanding the image to fit the rotated result. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image to rotate. /// The angle in degrees to perform the rotation. /// A delegate which is called as progress is made processing the image. /// The - public static Image Rotate(this Image source, float degrees, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + public static Image Rotate(this Image source, float degrees, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { return Rotate(source, degrees, true, progressHandler); } @@ -31,15 +31,15 @@ namespace ImageProcessorCore /// /// Rotates and flips an image by the given instructions. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image to rotate. /// The to perform the rotation. /// A delegate which is called as progress is made processing the image. /// The - public static Image Rotate(this Image source, RotateType rotateType, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + public static Image Rotate(this Image source, RotateType rotateType, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { return Rotate(source, (float)rotateType, false, progressHandler); } @@ -47,18 +47,18 @@ namespace ImageProcessorCore /// /// Rotates an image by the given angle in degrees. /// - /// The pixel format. - /// The packed format. long, float. + /// 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. /// A delegate which is called as progress is made processing the image. /// The - public static Image Rotate(this Image source, float degrees, bool expand, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + public static Image Rotate(this Image source, float degrees, bool expand, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { - RotateProcessor processor = new RotateProcessor { Angle = degrees, Expand = expand }; + RotateProcessor processor = new RotateProcessor { Angle = degrees, Expand = expand }; processor.OnProgress += progressHandler; try diff --git a/src/ImageProcessorCore/Samplers/RotateFlip.cs b/src/ImageProcessorCore/Samplers/RotateFlip.cs index 0cd513d34f..0cd406038f 100644 --- a/src/ImageProcessorCore/Samplers/RotateFlip.cs +++ b/src/ImageProcessorCore/Samplers/RotateFlip.cs @@ -8,22 +8,22 @@ namespace ImageProcessorCore using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Rotates and flips an image by the given instructions. /// - /// The pixel format. - /// The packed format. long, float. + /// The pixel format. + /// The packed format. uint, long, float. /// The image to rotate, flip, or both. /// The to perform the flip. /// A delegate which is called as progress is made processing the image. /// The - public static Image RotateFlip(this Image source, RotateType rotateType, FlipType flipType, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + public static Image RotateFlip(this Image source, RotateType rotateType, FlipType flipType, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { return source .Rotate(rotateType, progressHandler) diff --git a/src/ImageProcessorCore/Samplers/Skew.cs b/src/ImageProcessorCore/Samplers/Skew.cs index ab188ceeee..7c6e8b3ef6 100644 --- a/src/ImageProcessorCore/Samplers/Skew.cs +++ b/src/ImageProcessorCore/Samplers/Skew.cs @@ -8,23 +8,23 @@ namespace ImageProcessorCore using Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Skews an image by the given angles in degrees, expanding the image to fit the skewed result. /// - /// The pixel format. - /// The packed format. long, float. + /// 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. /// A delegate which is called as progress is made processing the image. /// The - public static Image Skew(this Image source, float degreesX, float degreesY, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + public static Image Skew(this Image source, float degreesX, float degreesY, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { return Skew(source, degreesX, degreesY, true, progressHandler); } @@ -32,19 +32,19 @@ namespace ImageProcessorCore /// /// Skews an image by the given angles in degrees. /// - /// The pixel format. - /// The packed format. long, float. + /// 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. /// A delegate which is called as progress is made processing the image. /// The - public static Image Skew(this Image source, float degreesX, float degreesY, bool expand, ProgressEventHandler progressHandler = null) - where T : IPackedVector - where TP : struct + public static Image Skew(this Image source, float degreesX, float degreesY, bool expand, ProgressEventHandler progressHandler = null) + where TColor : IPackedVector + where TPacked : struct { - SkewProcessor processor = new SkewProcessor { AngleX = degreesX, AngleY = degreesY, Expand = expand }; + SkewProcessor processor = new SkewProcessor { AngleX = degreesX, AngleY = degreesY, Expand = expand }; processor.OnProgress += progressHandler; try diff --git a/src/ImageProcessorCore/project.json b/src/ImageProcessorCore/project.json index 3bd2e9c545..51cd525980 100644 --- a/src/ImageProcessorCore/project.json +++ b/src/ImageProcessorCore/project.json @@ -35,6 +35,7 @@ "System.Numerics.Vectors": "4.1.1", "System.ObjectModel": "4.0.12", "System.Resources.ResourceManager": "4.0.1", + "System.Runtime.CompilerServices.Unsafe": "4.0.0", "System.Runtime.Extensions": "4.1.0", "System.Runtime.InteropServices": "4.1.0", "System.Runtime.Numerics": "4.0.1", diff --git a/tests/ImageProcessorCore.Benchmarks/Color/Clamp.cs b/tests/ImageProcessorCore.Benchmarks/General/Clamp.cs similarity index 92% rename from tests/ImageProcessorCore.Benchmarks/Color/Clamp.cs rename to tests/ImageProcessorCore.Benchmarks/General/Clamp.cs index 7af7010ab8..14ab553ab2 100644 --- a/tests/ImageProcessorCore.Benchmarks/Color/Clamp.cs +++ b/tests/ImageProcessorCore.Benchmarks/General/Clamp.cs @@ -1,6 +1,6 @@ using System; -namespace ImageProcessorCore.Benchmarks.Color +namespace ImageProcessorCore.Benchmarks.General { using BenchmarkDotNet.Attributes; @@ -27,7 +27,7 @@ namespace ImageProcessorCore.Benchmarks.Color { double value = 256; - if(value > 255) + if (value > 255) { return 255; } diff --git a/tests/ImageProcessorCore.Benchmarks/General/Copy.cs b/tests/ImageProcessorCore.Benchmarks/General/Copy.cs new file mode 100644 index 0000000000..de4dadffb7 --- /dev/null +++ b/tests/ImageProcessorCore.Benchmarks/General/Copy.cs @@ -0,0 +1,31 @@ +using System; +using System.Runtime.CompilerServices; + +namespace ImageProcessorCore.Benchmarks.General +{ + using BenchmarkDotNet.Attributes; + + public class Copy + { + private double[] source = new double[10000]; + + [Benchmark(Baseline = true, Description = "Copy using Array.Copy()")] + public double CopyArray() + { + + double[] destination = new double[10000]; + Array.Copy(source, destination, 10000); + + return destination[0]; + } + + [Benchmark(Description = "Copy using Unsafe")] + public unsafe double CopyUnsafe() + { + double[] destination = new double[10000]; + Unsafe.Copy(Unsafe.AsPointer(ref destination), ref source); + + return destination[0]; + } + } +} diff --git a/tests/ImageProcessorCore.Benchmarks/Image/GetSetPixel.cs b/tests/ImageProcessorCore.Benchmarks/Image/GetSetPixel.cs index c13b84064a..eb742404ef 100644 --- a/tests/ImageProcessorCore.Benchmarks/Image/GetSetPixel.cs +++ b/tests/ImageProcessorCore.Benchmarks/Image/GetSetPixel.cs @@ -10,7 +10,7 @@ public class GetSetPixel { - [Benchmark(Baseline = true, Description = "System.Drawing GetSet Pixel")] + [Benchmark(Baseline = true, Description = "System.Drawing GetSeTColor pixel")] public SystemColor ResizeSystemDrawing() { using (Bitmap source = new Bitmap(400, 400)) @@ -20,11 +20,11 @@ } } - [Benchmark(Description = "ImageProcessorCore GetSet Pixel")] + [Benchmark(Description = "ImageProcessorCore GetSeTColor pixel")] public CoreColor ResizeCore() { CoreImage image = new CoreImage(400, 400); - using (IPixelAccessor imagePixels = image.Lock()) + using (PixelAccessor imagePixels = image.Lock()) { imagePixels[200, 200] = CoreColor.White; return imagePixels[200, 200]; diff --git a/tests/ImageProcessorCore.Benchmarks/project.json b/tests/ImageProcessorCore.Benchmarks/project.json index 0ad417db50..f091d2a9d4 100644 --- a/tests/ImageProcessorCore.Benchmarks/project.json +++ b/tests/ImageProcessorCore.Benchmarks/project.json @@ -10,7 +10,8 @@ ] }, "buildOptions": { - "emitEntryPoint": true + "emitEntryPoint": true, + "allowUnsafe": true }, "dependencies": { "BenchmarkDotNet.Diagnostics.Windows": "0.9.9.116",