// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // namespace ImageProcessorCore { using Processors; using System; /// /// 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. /// 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 TColor : IPackedVector where TPacked : struct { return Pixelate(source, size, source.Bounds, progressHandler); } /// /// 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. /// /// 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 TColor : IPackedVector where TPacked : struct { if (size <= 0 || size > source.Height || size > source.Width) { throw new ArgumentOutOfRangeException(nameof(size)); } PixelateProcessor processor = new PixelateProcessor(size); processor.OnProgress += progressHandler; try { return source.Process(rectangle, processor); } finally { processor.OnProgress -= progressHandler; } } } }