diff --git a/src/ImageSharp/Filters/Convolution/DetectEdges.cs b/src/ImageSharp/Filters/Convolution/DetectEdges.cs index 649e0cf64..3ddcc6672 100644 --- a/src/ImageSharp/Filters/Convolution/DetectEdges.cs +++ b/src/ImageSharp/Filters/Convolution/DetectEdges.cs @@ -82,7 +82,7 @@ namespace ImageSharp switch (filter) { case EdgeDetection.Kayyali: - processor = new KayyaliSampler { Grayscale = grayscale }; + processor = new KayyaliProcessor { Grayscale = grayscale }; break; case EdgeDetection.Kirsch: diff --git a/src/ImageSharp/Filters/Effects/Pixelate.cs b/src/ImageSharp/Filters/Effects/Pixelate.cs index e7bd84c31..e69de29bb 100644 --- a/src/ImageSharp/Filters/Effects/Pixelate.cs +++ b/src/ImageSharp/Filters/Effects/Pixelate.cs @@ -1,55 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp -{ - using System; - - using Processors; - - /// - /// Extension methods for the type. - /// - public static partial class ImageExtensions - { - /// - /// Pixelates an image with the given pixel size. - /// - /// The pixel format. - /// The packed format. uint, long, float. - /// The image this method extends. - /// The size of the pixels. - /// The . - public static Image Pixelate(this Image source, int size = 4) - where TColor : struct, IPackedPixel - where TPacked : struct - { - return Pixelate(source, size, source.Bounds); - } - - /// - /// Pixelates an image with the given pixel size. - /// - /// The pixel format. - /// The packed format. uint, long, float. - /// The image this method extends. - /// The size of the pixels. - /// - /// The structure that specifies the portion of the image object to alter. - /// - /// The . - public static Image Pixelate(this Image source, int size, Rectangle rectangle) - where TColor : struct, IPackedPixel - where TPacked : struct - { - if (size <= 0 || size > source.Height || size > source.Width) - { - throw new ArgumentOutOfRangeException(nameof(size)); - } - - return source.Process(rectangle, new PixelateProcessor(size)); - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/Filters/Processors/Convolution/Convolution2DProcessor.cs b/src/ImageSharp/Filters/Processors/Convolution/Convolution2DProcessor.cs index c0d23adf1..afebcd8ed 100644 --- a/src/ImageSharp/Filters/Processors/Convolution/Convolution2DProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Convolution/Convolution2DProcessor.cs @@ -56,7 +56,6 @@ namespace ImageSharp.Processors int maxY = sourceBottom - 1; int maxX = endX - 1; - TColor[] target = new TColor[source.Width * source.Height]; using (PixelAccessor sourcePixels = source.Lock()) using (PixelAccessor targetPixels = target.Lock(source.Width, source.Height)) diff --git a/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/IEdgeDetectorSampler.cs b/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/IEdgeDetectorProcessor.cs similarity index 100% rename from src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/IEdgeDetectorSampler.cs rename to src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/IEdgeDetectorProcessor.cs diff --git a/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs b/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs index 5fbf54b30..039836230 100644 --- a/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs @@ -14,7 +14,7 @@ namespace ImageSharp.Processors /// The pixel format. /// The packed format. uint, long, float. [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] - public class KayyaliSampler : EdgeDetector2DProcessor + public class KayyaliProcessor : EdgeDetector2DProcessor where TColor : struct, IPackedPixel where TPacked : struct { diff --git a/src/ImageSharp/Filters/Processors/Effects/OilPaintingProcessor.cs b/src/ImageSharp/Filters/Processors/Effects/OilPaintingProcessor.cs index f368152fc..cddf74af6 100644 --- a/src/ImageSharp/Filters/Processors/Effects/OilPaintingProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Effects/OilPaintingProcessor.cs @@ -10,7 +10,7 @@ namespace ImageSharp.Processors using System.Threading.Tasks; /// - /// An to apply an oil painting effect to an . + /// An to apply an oil painting effect to an . /// /// Adapted from by Dewald Esterhuizen. /// The pixel format. diff --git a/src/ImageSharp/Filters/Processors/Effects/PixelateProcessor.cs b/src/ImageSharp/Filters/Processors/Effects/PixelateProcessor.cs index 347dc39c9..17b0450e0 100644 --- a/src/ImageSharp/Filters/Processors/Effects/PixelateProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Effects/PixelateProcessor.cs @@ -10,7 +10,7 @@ namespace ImageSharp.Processors using System.Threading.Tasks; /// - /// An to pixelate the colors of an . + /// An to pixelate the colors of an . /// /// The pixel format. /// The packed format. uint, long, float. diff --git a/src/ImageSharp/Filters/Transforms/EntropyCrop.cs b/src/ImageSharp/Filters/Transforms/EntropyCrop.cs index 49757039f..06902888d 100644 --- a/src/ImageSharp/Filters/Transforms/EntropyCrop.cs +++ b/src/ImageSharp/Filters/Transforms/EntropyCrop.cs @@ -26,7 +26,6 @@ namespace ImageSharp { EntropyCropProcessor processor = new EntropyCropProcessor(threshold); return source.Process(source.Bounds, processor); - // return source.Process(source.Width, source.Height, source.Bounds, Rectangle.Empty, processor); } } } \ No newline at end of file diff --git a/src/ImageSharp/IO/EndianBinaryReader.cs b/src/ImageSharp/IO/EndianBinaryReader.cs index 3b12401b6..105647675 100644 --- a/src/ImageSharp/IO/EndianBinaryReader.cs +++ b/src/ImageSharp/IO/EndianBinaryReader.cs @@ -42,17 +42,23 @@ namespace ImageSharp.IO private bool disposed; /// - /// Equivalent of System.IO.BinaryWriter, but with either endianness, depending on + /// Initializes a new instance of the class. + /// Equivalent of , but with either endianness, depending on /// the EndianBitConverter it is constructed with. /// - /// Converter to use when reading data - /// Stream to read data from + /// + /// Converter to use when reading data + /// + /// + /// Stream to read data from + /// public EndianBinaryReader(EndianBitConverter bitConverter, Stream stream) : this(bitConverter, stream, Encoding.UTF8) { } /// + /// Initializes a new instance of the class. /// Constructs a new binary reader with the given bit converter, reading /// to the given stream, using the given encoding. /// diff --git a/src/ImageSharp/Image/ImageProcessingExtensions.cs b/src/ImageSharp/Image/ImageProcessingExtensions.cs index 7ebaf8f15..69c283f9f 100644 --- a/src/ImageSharp/Image/ImageProcessingExtensions.cs +++ b/src/ImageSharp/Image/ImageProcessingExtensions.cs @@ -48,88 +48,6 @@ namespace ImageSharp return PerformAction(source, (sourceImage) => processor.Apply(sourceImage, sourceRectangle)); } - /// - /// Applies the processor to the image. - /// This method does not resize the target image. - /// - /// The pixel format. - /// The packed format. uint, long, float. - /// The image this method extends. - /// The processor to apply to the image. - /// The . - internal static Image Process(this Image source, IImageSamplingProcessor processor) - where TColor : struct, IPackedPixel - where TPacked : struct - { - return Process(source, source.Bounds, processor); - } - - /// - /// Applies the processor to the image. - /// This method does not resize the target image. - /// - /// The pixel format. - /// The packed format. uint, long, float. - /// The image this method extends. - /// - /// The structure that specifies the portion of the image object to draw. - /// - /// The processors to apply to the image. - /// The . - internal static Image Process(this Image source, Rectangle sourceRectangle, IImageSamplingProcessor processor) - where TColor : struct, IPackedPixel - where TPacked : struct - { - return PerformAction(source, true, (sourceImage, targetImage) => processor.Apply(targetImage, sourceImage, sourceRectangle)); - } - - /// - /// Applies the processor to the image. - /// - /// This method resizes the image. - /// - /// - /// The pixel format. - /// The packed format. 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, IImageSamplingProcessor sampler) - where TColor : struct, IPackedPixel - where TPacked : struct - { - return Process(source, width, height, source.Bounds, default(Rectangle), sampler); - } - - /// - /// Applies the processor to the image. - /// - /// 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 source image. Cannot be null. - /// The target image width. - /// The target image height. - /// - /// The structure that specifies the portion of the image object to draw. - /// - /// - /// The structure that specifies the location and size of the drawn image. - /// 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, IImageSamplingProcessor sampler) - where TColor : struct, IPackedPixel - where TPacked : struct - { - return PerformAction(source, false, (sourceImage, targetImage) => sampler.Apply(targetImage, sourceImage, width, height, targetRectangle, sourceRectangle)); - } - /// /// Performs the given action on the source image. /// @@ -151,53 +69,5 @@ namespace ImageSharp return source; } - - /// - /// Performs the given action on the source image. - /// - /// The pixel format. - /// The packed format. 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 TColor : struct, IPackedPixel - where TPacked : struct - { - Image transformedImage = clone - ? new Image(source) - : new Image(); - - // Several properties still require copying - if (!clone) - { - transformedImage.CopyProperties(source); - } - - action(source, transformedImage); - - 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 }; - - action(sourceFrame, tranformedFrame); - - if (!clone) - { - transformedImage.Frames.Add(tranformedFrame); - } - else - { - transformedImage.Frames[i] = tranformedFrame; - } - } - - source = transformedImage; - return source; - } } } diff --git a/src/ImageSharp/Samplers/Processors/IImageSamplingProcessor.cs b/src/ImageSharp/Samplers/Processors/IImageSamplingProcessor.cs deleted file mode 100644 index 756c96612..000000000 --- a/src/ImageSharp/Samplers/Processors/IImageSamplingProcessor.cs +++ /dev/null @@ -1,58 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp.Processors -{ - /// - /// Encapsulates methods to alter the pixels of an image. The processor creates a copy of the original image to operate on. - /// - /// The pixel format. - /// The packed format. uint, long, float. - public interface IImageSamplingProcessor : IImageProcessor - where TColor : struct, IPackedPixel - where TPacked : struct - { - /// - /// Applies the process to the specified portion of the specified . - /// - /// Target image to apply the process to. - /// The source image. Cannot be null. - /// - /// The structure that specifies the portion of the image object to draw. - /// - /// - /// The method keeps the source image unchanged and returns the - /// the result of image processing filter as new image. - /// - /// - /// is null or is null. - /// - /// - /// doesnt fit the dimension of the image. - /// - void Apply(ImageBase target, ImageBase source, Rectangle sourceRectangle); - - /// - /// 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. - /// The source image. Cannot be null. - /// The target width. - /// The target height. - /// - /// The structure that specifies the location and size of the drawn image. - /// The image is scaled to fit the rectangle. - /// - /// - /// The structure that specifies the portion of the image object to draw. - /// - /// - /// 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); - } -} diff --git a/src/ImageSharp/Samplers/Processors/ImageSamplingProcessor.cs b/src/ImageSharp/Samplers/Processors/ImageSamplingProcessor.cs deleted file mode 100644 index aa9d583a4..000000000 --- a/src/ImageSharp/Samplers/Processors/ImageSamplingProcessor.cs +++ /dev/null @@ -1,119 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp.Processors -{ - using System; - - /// - /// Encapsulates methods to alter the pixels of an image. The processor creates a copy of the original image to operate on. - /// - /// The pixel format. - /// The packed format. uint, long, float. - public abstract class ImageSamplingProcessor : ImageProcessor, IImageSamplingProcessor - where TColor : struct, IPackedPixel - where TPacked : struct - { - /// - public void Apply(ImageBase target, ImageBase source, Rectangle sourceRectangle) - { - try - { - this.OnApply(target, source, target.Bounds, sourceRectangle); - - this.Apply(target, source, target.Bounds, sourceRectangle, sourceRectangle.Y, sourceRectangle.Bottom); - - this.AfterApply(target, source, target.Bounds, sourceRectangle); - } - catch (Exception ex) - { - throw new ImageProcessingException($"An error occured when processing the image using {this.GetType().Name}. See the inner exception for more detail.", ex); - } - } - - /// - public void Apply(ImageBase target, ImageBase source, int width, int height, Rectangle targetRectangle = default(Rectangle), Rectangle sourceRectangle = default(Rectangle)) - { - try - { - TColor[] pixels = new TColor[width * height]; - target.SetPixels(width, height, pixels); - - // Ensure we always have bounds. - if (sourceRectangle == Rectangle.Empty) - { - sourceRectangle = source.Bounds; - } - - if (targetRectangle == Rectangle.Empty) - { - targetRectangle = target.Bounds; - } - - this.OnApply(target, source, targetRectangle, sourceRectangle); - - this.Apply(target, source, targetRectangle, sourceRectangle, targetRectangle.Y, targetRectangle.Bottom); - - this.AfterApply(target, source, target.Bounds, sourceRectangle); - } - catch (Exception ex) - { - throw new ImageProcessingException($"An error occured when processing the image using {this.GetType().Name}. See the inner exception for more detail.", ex); - } - } - - /// - /// 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. - /// The source image. Cannot be null. - /// - /// The structure that specifies the location and size of the drawn image. - /// The image is scaled to fit the rectangle. - /// - /// - /// The structure that specifies the portion of the image object to draw. - /// - /// 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 method keeps the source image unchanged and returns the the result of image process as new image. - /// - public abstract void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY); - - /// - /// This method is called before the process is applied to prepare the processor. - /// - /// Target image to apply the process to. - /// The source image. Cannot be null. - /// - /// The structure that specifies the location and size of the drawn image. - /// The image is scaled to fit the rectangle. - /// - /// - /// The structure that specifies the portion of the image object to draw. - /// - protected virtual void OnApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) - { - } - - /// - /// This method is called after the process is applied to prepare the processor. - /// - /// Target image to apply the process to. - /// The source image. Cannot be null. - /// - /// The structure that specifies the location and size of the drawn image. - /// The image is scaled to fit the rectangle. - /// - /// - /// The structure that specifies the portion of the image object to draw. - /// - protected virtual void AfterApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) - { - } - } -} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processors/Filters/GaussianSharpenTest.cs b/tests/ImageSharp.Tests/Processors/Filters/GaussianSharpenTest.cs index 75e2020cd..69c24ab3b 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/GaussianSharpenTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/GaussianSharpenTest.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // diff --git a/tests/ImageSharp.Tests/Processors/Filters/OilPaintTest.cs b/tests/ImageSharp.Tests/Processors/Filters/OilPaintTest.cs index e6fa22a6f..e69de29bb 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/OilPaintTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/OilPaintTest.cs @@ -1,66 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp.Tests -{ - using System; - using System.IO; - - using Xunit; - - public class OilPaintTest : FileTestBase - { - public static readonly TheoryData> OilPaintValues - = new TheoryData> - { - new Tuple(15, 10), - new Tuple(8, 5) - }; - - [Theory] - [MemberData(nameof(OilPaintValues))] - public void ImageShouldApplyOilPaintFilter(Tuple value) - { - string path = CreateOutputDirectory("OilPaint"); - - foreach (TestFile file in Files) - { - string filename = file.GetFileName(value); - Image image = file.CreateImage(); - - using (FileStream output = File.OpenWrite($"{path}/{filename}")) - { - if (value.Item2 < image.Width && value.Item2 < image.Height) - { - image.OilPaint(value.Item1, value.Item2) - .Save(output); - } - } - } - } - - [Theory] - [MemberData(nameof(OilPaintValues))] - public void ImageShouldApplyOilPaintFilterInBox(Tuple value) - { - string path = CreateOutputDirectory("OilPaint"); - - foreach (TestFile file in Files) - { - string filename = file.GetFileName(value + "-InBox"); - Image image = file.CreateImage(); - - using (FileStream output = File.OpenWrite($"{path}/{filename}")) - { - if (value.Item2 < image.Width && value.Item2 < image.Height) - { - image.OilPaint(value.Item1, value.Item2, new Rectangle(image.Width / 4, image.Width / 4, image.Width / 2, image.Height / 2)) - .Save(output); - } - } - } - } - } -} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processors/Filters/PixelateTest.cs b/tests/ImageSharp.Tests/Processors/Filters/PixelateTest.cs index 8655dfb96..e69de29bb 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/PixelateTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/PixelateTest.cs @@ -1,59 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp.Tests -{ - using System.IO; - - using Xunit; - - public class PixelateTest : FileTestBase - { - public static readonly TheoryData PixelateValues - = new TheoryData - { - 4 , - 8 - }; - - [Theory] - [MemberData(nameof(PixelateValues))] - public void ImageShouldApplyPixelateFilter(int value) - { - string path = CreateOutputDirectory("Pixelate"); - - foreach (TestFile file in Files) - { - string filename = file.GetFileName(value); - Image image = file.CreateImage(); - - using (FileStream output = File.OpenWrite($"{path}/{filename}")) - { - image.Pixelate(value) - .Save(output); - } - } - } - - [Theory] - [MemberData(nameof(PixelateValues))] - public void ImageShouldApplyPixelateFilterInBox(int value) - { - string path = CreateOutputDirectory("Pixelate"); - - foreach (TestFile file in Files) - { - string filename = file.GetFileName(value + "-InBox"); - Image image = file.CreateImage(); - - using (FileStream output = File.OpenWrite($"{path}/{filename}")) - { - image.Pixelate(value, new Rectangle(10, 10, image.Width / 2, image.Height / 2)) - .Save(output); - } - } - } - } -} \ No newline at end of file