mirror of https://github.com/SixLabors/ImageSharp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
2.6 KiB
55 lines
2.6 KiB
// <copyright file="OilPainting.cs" company="James Jackson-South">
|
|
// Copyright (c) James Jackson-South and contributors.
|
|
// Licensed under the Apache License, Version 2.0.
|
|
// </copyright>
|
|
|
|
namespace ImageSharp
|
|
{
|
|
using System;
|
|
|
|
using Processing.Processors;
|
|
|
|
/// <summary>
|
|
/// Extension methods for the <see cref="Image{TColor}"/> type.
|
|
/// </summary>
|
|
public static partial class ImageExtensions
|
|
{
|
|
/// <summary>
|
|
/// Alters the colors of the image recreating an oil painting effect.
|
|
/// </summary>
|
|
/// <typeparam name="TColor">The pixel format.</typeparam>
|
|
/// <param name="source">The image this method extends.</param>
|
|
/// <param name="levels">The number of intensity levels. Higher values result in a broader range of color intensities forming part of the result image.</param>
|
|
/// <param name="brushSize">The number of neighboring pixels used in calculating each individual pixel value.</param>
|
|
/// <returns>The <see cref="Image{TColor}"/>.</returns>
|
|
public static Image<TColor> OilPaint<TColor>(this Image<TColor> source, int levels = 10, int brushSize = 15)
|
|
where TColor : struct, IPackedPixel, IEquatable<TColor>
|
|
{
|
|
return OilPaint(source, levels, brushSize, source.Bounds);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Alters the colors of the image recreating an oil painting effect.
|
|
/// </summary>
|
|
/// <typeparam name="TColor">The pixel format.</typeparam>
|
|
/// <param name="source">The image this method extends.</param>
|
|
/// <param name="levels">The number of intensity levels. Higher values result in a broader range of color intensities forming part of the result image.</param>
|
|
/// <param name="brushSize">The number of neighboring pixels used in calculating each individual pixel value.</param>
|
|
/// <param name="rectangle">
|
|
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|
/// </param>
|
|
/// <returns>The <see cref="Image{TColor}"/>.</returns>
|
|
public static Image<TColor> OilPaint<TColor>(this Image<TColor> source, int levels, int brushSize, Rectangle rectangle)
|
|
where TColor : struct, IPackedPixel, IEquatable<TColor>
|
|
{
|
|
Guard.MustBeGreaterThan(levels, 0, nameof(levels));
|
|
|
|
if (brushSize <= 0 || brushSize > source.Height || brushSize > source.Width)
|
|
{
|
|
throw new ArgumentOutOfRangeException(nameof(brushSize));
|
|
}
|
|
|
|
return source.Apply(rectangle, new OilPaintingProcessor<TColor>(levels, brushSize));
|
|
}
|
|
}
|
|
}
|