-
Notifications
You must be signed in to change notification settings - Fork 979
Expand file tree
/
Copy pathMirrorPadProcessor.cs
More file actions
56 lines (49 loc) · 2.41 KB
/
MirrorPadProcessor.cs
File metadata and controls
56 lines (49 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="MirrorPadProcessor.cs" company="OxyPlot">
// Copyright (c) 2014 OxyPlot contributors
// </copyright>
// <summary>
// Provides an an ImageProcessor that performs a single-pizel mirror/clamp along the edge of an image.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
#nullable enable
namespace OxyPlot.ImageSharp
{
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
/// <summary>
/// Performs a single-pizel mirror/clamp along the edge of the image, which is used to assist with drawing non-pixel aligned and interpolate images.
/// </summary>
internal class MirrorPadProcessor : IImageProcessor
{
private class MirrorPadImplementation<TPixel> : ImageProcessor<TPixel> where TPixel : unmanaged, IPixel<TPixel>
{
public MirrorPadImplementation(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)
: base(configuration, source, sourceRectangle)
{
}
protected override void OnFrameApply(ImageFrame<TPixel> source)
{
source[0, 0] = source[1, 1];
source[source.Width - 1, 0] = source[source.Width - 2, 1];
source[0, source.Height - 1] = source[1, source.Height - 2];
source[source.Width - 1, source.Height - 1] = source[source.Width - 2, source.Height - 2];
for (int x = 1; x < source.Width - 1; x++)
{
source[x, 0] = source[x, 1];
source[x, source.Height - 1] = source[x, source.Height - 2];
}
for (int y = 1; y < source.Height - 1; y++)
{
source[0, y] = source[1, y];
source[source.Width - 1, y] = source[source.Width - 2, y];
}
}
}
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle) where TPixel : unmanaged, IPixel<TPixel>
{
return new MirrorPadImplementation<TPixel>(configuration, source, sourceRectangle);
}
}
}