mirror of https://github.com/SixLabors/ImageSharp
Browse Source
VS 2015 definitely has a bug that deletes the contents of files when dragging/dropping within a solution.af/merge-core
3 changed files with 174 additions and 0 deletions
@ -0,0 +1,55 @@ |
|||
// <copyright file="Pixelate.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 Processors; |
|||
|
|||
/// <summary>
|
|||
/// Extension methods for the <see cref="Image{TColor, TPacked}"/> type.
|
|||
/// </summary>
|
|||
public static partial class ImageExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Pixelates an image with the given pixel size.
|
|||
/// </summary>
|
|||
/// <typeparam name="TColor">The pixel format.</typeparam>
|
|||
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="size">The size of the pixels.</param>
|
|||
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
|
|||
public static Image<TColor, TPacked> Pixelate<TColor, TPacked>(this Image<TColor, TPacked> source, int size = 4) |
|||
where TColor : struct, IPackedPixel<TPacked> |
|||
where TPacked : struct |
|||
{ |
|||
return Pixelate(source, size, source.Bounds); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Pixelates an image with the given pixel size.
|
|||
/// </summary>
|
|||
/// <typeparam name="TColor">The pixel format.</typeparam>
|
|||
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="size">The size of the pixels.</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, TPacked}"/>.</returns>
|
|||
public static Image<TColor, TPacked> Pixelate<TColor, TPacked>(this Image<TColor, TPacked> source, int size, Rectangle rectangle) |
|||
where TColor : struct, IPackedPixel<TPacked> |
|||
where TPacked : struct |
|||
{ |
|||
if (size <= 0 || size > source.Height || size > source.Width) |
|||
{ |
|||
throw new ArgumentOutOfRangeException(nameof(size)); |
|||
} |
|||
|
|||
return source.Process(rectangle, new PixelateProcessor<TColor, TPacked>(size)); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,60 @@ |
|||
// <copyright file="OilPaintTest.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp.Tests |
|||
{ |
|||
using System; |
|||
using System.IO; |
|||
|
|||
using Xunit; |
|||
|
|||
public class OilPaintTest : FileTestBase |
|||
{ |
|||
public static readonly TheoryData<Tuple<int, int>> OilPaintValues |
|||
= new TheoryData<Tuple<int, int>> |
|||
{ |
|||
new Tuple<int, int>(15,10), |
|||
new Tuple<int, int>(6,5) |
|||
}; |
|||
|
|||
[Theory] |
|||
[MemberData(nameof(OilPaintValues))] |
|||
public void ImageShouldApplyOilPaintFilter(Tuple<int, int> 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}")) |
|||
{ |
|||
image.OilPaint(value.Item1, value.Item2) |
|||
.Save(output); |
|||
} |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[MemberData(nameof(OilPaintValues))] |
|||
public void ImageShouldApplyOilPaintFilterInBox(Tuple<int, int> 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}")) |
|||
{ |
|||
image.OilPaint(value.Item1, value.Item2, new Rectangle(10, 10, image.Width / 2, image.Height / 2)) |
|||
.Save(output); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,59 @@ |
|||
// <copyright file="PixelateTest.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp.Tests |
|||
{ |
|||
using System.IO; |
|||
|
|||
using Xunit; |
|||
|
|||
public class PixelateTest : FileTestBase |
|||
{ |
|||
public static readonly TheoryData<int> PixelateValues |
|||
= new TheoryData<int> |
|||
{ |
|||
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); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue