Browse Source

Move Oilpaint

af/merge-core
James Jackson-South 10 years ago
parent
commit
7e380fe89b
  1. 0
      src/ImageSharp/Filters/Effects/OilPainting.cs
  2. 14
      src/ImageSharp/Filters/Processors/Effects/OilPaintingProcessor.cs
  3. 18
      tests/ImageSharp.Tests/Processors/Filters/OilPaintTest.cs

0
src/ImageSharp/Samplers/Effects/OilPainting.cs → src/ImageSharp/Filters/Effects/OilPainting.cs

14
src/ImageSharp/Samplers/Processors/Effects/OilPaintingProcessor.cs → src/ImageSharp/Filters/Processors/Effects/OilPaintingProcessor.cs

@ -15,12 +15,12 @@ namespace ImageSharp.Processors
/// <remarks>Adapted from <see href="https://softwarebydefault.com/2013/06/29/oil-painting-cartoon-filter/"/> by Dewald Esterhuizen.</remarks>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class OilPaintingProcessor<TColor, TPacked> : ImageSamplingProcessor<TColor, TPacked>
public class OilPaintingProcessor<TColor, TPacked> : ImageFilteringProcessor<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct
{
/// <summary>
/// Initializes a new instance of the <see cref="OilPaintingProcessor{TColor,TPacked}"/> class.
/// Initializes a new instance of the <see cref="OilPaintingProcessor{TColor,TPacked}"/> class.
/// </summary>
/// <param name="levels">
/// The number of intensity levels. Higher values result in a broader range of color intensities forming part of the result image.
@ -48,7 +48,7 @@ namespace ImageSharp.Processors
public int BrushSize { get; }
/// <inheritdoc/>
public override void Apply(ImageBase<TColor, TPacked> target, ImageBase<TColor, TPacked> source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
protected override void Apply(ImageBase<TColor, TPacked> source, Rectangle sourceRectangle, int startY, int endY)
{
int startX = sourceRectangle.X;
int endX = sourceRectangle.Right;
@ -67,8 +67,9 @@ namespace ImageSharp.Processors
startX = 0;
}
TColor[] target = new TColor[source.Width * source.Height];
using (PixelAccessor<TColor, TPacked> sourcePixels = source.Lock())
using (PixelAccessor<TColor, TPacked> targetPixels = target.Lock())
using (PixelAccessor<TColor, TPacked> targetPixels = target.Lock<TColor, TPacked>(source.Width, source.Height))
{
Parallel.For(
minY,
@ -142,14 +143,15 @@ namespace ImageSharp.Processors
float green = Math.Abs(greenBin[maxIndex] / maxIntensity);
float blue = Math.Abs(blueBin[maxIndex] / maxIntensity);
Vector4 targetColor = targetPixels[x, y].ToVector4();
TColor packed = default(TColor);
packed.PackFromVector4(new Vector4(red, green, blue, targetColor.Z));
packed.PackFromVector4(new Vector4(red, green, blue, sourcePixels[x, y].ToVector4().W));
targetPixels[x, y] = packed;
}
}
});
}
source.SetPixels(source.Width, source.Height, target);
}
}
}

18
tests/ImageSharp.Tests/Processors/Samplers/OilPaintTest.cs → tests/ImageSharp.Tests/Processors/Filters/OilPaintTest.cs

@ -15,8 +15,8 @@ namespace ImageSharp.Tests
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)
new Tuple<int, int>(15, 10),
new Tuple<int, int>(8, 5)
};
[Theory]
@ -32,8 +32,11 @@ namespace ImageSharp.Tests
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.OilPaint(value.Item1, value.Item2)
.Save(output);
if (value.Item2 < image.Width && value.Item2 < image.Height)
{
image.OilPaint(value.Item1, value.Item2)
.Save(output);
}
}
}
}
@ -51,8 +54,11 @@ namespace ImageSharp.Tests
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);
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);
}
}
}
}
Loading…
Cancel
Save