// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // namespace ImageSharp { using System; using Processing.Processors; /// /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Pixelates an image with the given pixel size. /// /// The pixel format. /// 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, IEquatable { return Pixelate(source, size, source.Bounds); } /// /// Pixelates an image with the given pixel size. /// /// The pixel format. /// 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, IEquatable { if (size <= 0 || size > source.Height || size > source.Width) { throw new ArgumentOutOfRangeException(nameof(size)); } source.ApplyProcessor(new PixelateProcessor(size), rectangle); return source; } } }