2013-11-06 11:48:41 +13:00
|
|
|
|
#region License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
2020-02-05 20:19:48 +13:00
|
|
|
|
Copyright (c) 2007-2020 ShareX Team
|
2013-11-06 11:48:41 +13:00
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
|
|
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#endregion License Information (GPL v3)
|
|
|
|
|
|
2014-12-11 09:25:20 +13:00
|
|
|
|
using ShareX.HelpersLib;
|
2018-12-12 20:28:34 +13:00
|
|
|
|
using System;
|
2013-11-06 11:48:41 +13:00
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
|
2014-12-11 09:25:20 +13:00
|
|
|
|
namespace ShareX.ImageEffectsLib
|
2013-11-06 11:48:41 +13:00
|
|
|
|
{
|
2013-11-09 16:13:49 +13:00
|
|
|
|
[Description("Gaussian blur")]
|
2013-11-06 11:48:41 +13:00
|
|
|
|
internal class GaussianBlur : ImageEffect
|
|
|
|
|
{
|
2018-12-13 08:07:10 +13:00
|
|
|
|
private double sigma;
|
|
|
|
|
private int size;
|
2018-12-12 20:28:34 +13:00
|
|
|
|
|
|
|
|
|
[DefaultValue(0.7955555)]
|
|
|
|
|
public double Sigma
|
|
|
|
|
{
|
2018-12-13 08:07:10 +13:00
|
|
|
|
get => sigma;
|
2018-12-13 12:38:16 +13:00
|
|
|
|
set => sigma = Math.Max(value, 0.1);
|
2018-12-12 20:28:34 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[DefaultValue(3)]
|
|
|
|
|
public int Size
|
|
|
|
|
{
|
2018-12-13 08:07:10 +13:00
|
|
|
|
get => size;
|
2018-12-12 20:28:34 +13:00
|
|
|
|
set
|
|
|
|
|
{
|
2019-06-13 00:29:16 +12:00
|
|
|
|
size = value.Max(1);
|
2018-12-12 20:28:34 +13:00
|
|
|
|
|
2018-12-13 08:07:10 +13:00
|
|
|
|
if (size.IsEvenNumber())
|
2018-12-12 20:28:34 +13:00
|
|
|
|
{
|
2018-12-13 08:07:10 +13:00
|
|
|
|
size++;
|
2018-12-12 20:28:34 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public GaussianBlur()
|
|
|
|
|
{
|
|
|
|
|
this.ApplyDefaultPropertyValues();
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-22 10:41:08 +13:00
|
|
|
|
public override Bitmap Apply(Bitmap bmp)
|
2018-12-12 20:28:34 +13:00
|
|
|
|
{
|
2018-12-13 12:38:16 +13:00
|
|
|
|
ConvolutionMatrix kernelHoriz = ConvolutionMatrixManager.GaussianBlur(1, size, sigma);
|
2018-12-12 20:28:34 +13:00
|
|
|
|
|
2019-04-29 14:06:06 +12:00
|
|
|
|
ConvolutionMatrix kernelVert = new ConvolutionMatrix(size, 1)
|
|
|
|
|
{
|
|
|
|
|
ConsiderAlpha = kernelHoriz.ConsiderAlpha
|
|
|
|
|
};
|
|
|
|
|
|
2018-12-13 08:07:10 +13:00
|
|
|
|
for (int i = 0; i < size; i++)
|
2018-12-12 20:28:34 +13:00
|
|
|
|
{
|
2018-12-13 12:38:16 +13:00
|
|
|
|
kernelVert[i, 0] = kernelHoriz[0, i];
|
2018-12-12 20:28:34 +13:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-22 10:41:08 +13:00
|
|
|
|
using (bmp)
|
|
|
|
|
using (Bitmap horizPass = kernelHoriz.Apply(bmp))
|
2013-11-06 11:48:41 +13:00
|
|
|
|
{
|
2018-12-13 12:38:16 +13:00
|
|
|
|
return kernelVert.Apply(horizPass);
|
2013-11-06 11:48:41 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|