-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using FilterLib.Reporting; | ||
using FilterLib.Util; | ||
using System; | ||
using System.Drawing; | ||
|
||
namespace FilterLib.Filters.Border | ||
{ | ||
/// <summary> | ||
/// Fade border filter. | ||
/// </summary> | ||
[Filter] | ||
public sealed class FadeBorderFilter : FilterInPlaceBase | ||
{ | ||
/// <summary> | ||
/// Border width. | ||
/// </summary> | ||
[FilterParam] | ||
public Util.Size Width { get; set; } | ||
|
||
/// <summary> | ||
/// Border color. | ||
/// </summary> | ||
[FilterParam] | ||
public RGB Color { get; set; } | ||
|
||
/// <summary> | ||
/// Constructor. | ||
/// </summary> | ||
public FadeBorderFilter() : this(Util.Size.Absolute(0), new RGB(0, 0, 0)) { } | ||
|
||
/// <summary> | ||
/// Constructor. | ||
/// </summary> | ||
/// <param name="width">Border width</param> | ||
/// <param name="color">Border color</param> | ||
public FadeBorderFilter(Util.Size width, RGB color) | ||
{ | ||
this.Width = width; | ||
this.Color = color; | ||
} | ||
|
||
/// <summary> | ||
/// Apply filter by modifying the original image. | ||
/// </summary> | ||
/// <param name="image">Input image</param> | ||
/// <param name="reporter">Reporter (optional)</param> | ||
public override void ApplyInPlace(Bitmap image, IReporter reporter = null) | ||
{ | ||
reporter?.Start(); | ||
int w = image.Width, h = image.Height; | ||
int borderWidth = Width.ToAbsolute(Math.Max(w, h)); | ||
using (Graphics gfx = Graphics.FromImage(image)) | ||
{ | ||
// Draw rectangles with decreasing alpha value | ||
for (int k = 0; k < borderWidth; ++k) | ||
{ | ||
using Pen pen = new Pen(System.Drawing.Color.FromArgb((int)(255 - k / (float)(borderWidth - 1) * 255), Color.R, Color.G, Color.B)); | ||
gfx.DrawLine(pen, 0, k, w, k); | ||
gfx.DrawLine(pen, k, 0, k, h); | ||
gfx.DrawLine(pen, 0, h - 1 - k, w, h - 1 - k); | ||
gfx.DrawLine(pen, w - 1 - k, 0, w - 1 - k, h); | ||
reporter?.Report(k, 0, borderWidth - 1); | ||
} | ||
} | ||
reporter?.Done(); | ||
} | ||
} | ||
} |