From 8620fdb092e3014a0aebd328b61f8434cea39be8 Mon Sep 17 00:00:00 2001 From: Jaex Date: Wed, 6 Nov 2013 01:10:27 +0200 Subject: [PATCH] Added MatrixConvolution effect --- .../Adjustments/{Matrix.cs => MatrixColor.cs} | 20 +---- ImageEffectsLib/Filters/MatrixConvolution.cs | 86 +++++++++++++++++++ ImageEffectsLib/ImageEffectsForm.cs | 3 +- ImageEffectsLib/ImageEffectsLib.csproj | 3 +- 4 files changed, 92 insertions(+), 20 deletions(-) rename ImageEffectsLib/Adjustments/{Matrix.cs => MatrixColor.cs} (97%) create mode 100644 ImageEffectsLib/Filters/MatrixConvolution.cs diff --git a/ImageEffectsLib/Adjustments/Matrix.cs b/ImageEffectsLib/Adjustments/MatrixColor.cs similarity index 97% rename from ImageEffectsLib/Adjustments/Matrix.cs rename to ImageEffectsLib/Adjustments/MatrixColor.cs index dff3d9c85..61a99debe 100644 --- a/ImageEffectsLib/Adjustments/Matrix.cs +++ b/ImageEffectsLib/Adjustments/MatrixColor.cs @@ -30,69 +30,53 @@ You should have received a copy of the GNU General Public License namespace ImageEffectsLib { - internal class Matrix : ImageEffect + internal class MatrixColor : ImageEffect { [DefaultValue(1f), Description("Red = (Red * Rr) + (Green * Rg) + (Blue * Rb) + (Alpha * Ra) + Ro")] public float Rr { get; set; } - [DefaultValue(0f)] public float Rg { get; set; } - [DefaultValue(0f)] public float Rb { get; set; } - [DefaultValue(0f)] public float Ra { get; set; } - [DefaultValue(0f)] public float Ro { get; set; } [DefaultValue(0f)] public float Gr { get; set; } - [DefaultValue(1f)] public float Gg { get; set; } - [DefaultValue(0f)] public float Gb { get; set; } - [DefaultValue(0f)] public float Ga { get; set; } - [DefaultValue(0f)] public float Go { get; set; } [DefaultValue(0f)] public float Br { get; set; } - [DefaultValue(0f)] public float Bg { get; set; } - [DefaultValue(1f)] public float Bb { get; set; } - [DefaultValue(0f)] public float Ba { get; set; } - [DefaultValue(0f)] public float Bo { get; set; } [DefaultValue(0f)] public float Ar { get; set; } - [DefaultValue(0f)] public float Ag { get; set; } - [DefaultValue(0f)] public float Ab { get; set; } - [DefaultValue(1f)] public float Aa { get; set; } - [DefaultValue(0f)] public float Ao { get; set; } - public Matrix() + public MatrixColor() { this.ApplyDefaultPropertyValues(); } diff --git a/ImageEffectsLib/Filters/MatrixConvolution.cs b/ImageEffectsLib/Filters/MatrixConvolution.cs new file mode 100644 index 000000000..1891551af --- /dev/null +++ b/ImageEffectsLib/Filters/MatrixConvolution.cs @@ -0,0 +1,86 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (C) 2008-2013 ShareX Developers + + 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 . +*/ + +#endregion License Information (GPL v3) + +using HelpersLib; +using System.ComponentModel; +using System.Drawing; + +namespace ImageEffectsLib +{ + internal class MatrixConvolution : ImageEffect + { + [DefaultValue(0)] + public int X0Y0 { get; set; } + [DefaultValue(0)] + public int X1Y0 { get; set; } + [DefaultValue(0)] + public int X2Y0 { get; set; } + + [DefaultValue(0)] + public int X0Y1 { get; set; } + [DefaultValue(1)] + public int X1Y1 { get; set; } + [DefaultValue(0)] + public int X2Y1 { get; set; } + + [DefaultValue(0)] + public int X0Y2 { get; set; } + [DefaultValue(0)] + public int X1Y2 { get; set; } + [DefaultValue(0)] + public int X2Y2 { get; set; } + + [DefaultValue(1)] + public int Factor { get; set; } + + [DefaultValue(0)] + public int Offset { get; set; } + + public MatrixConvolution() + { + this.ApplyDefaultPropertyValues(); + } + + public override Image Apply(Image img) + { + using (img) + { + ConvolutionMatrix cm = new ConvolutionMatrix(); + cm.Matrix[0, 0] = X0Y0; + cm.Matrix[1, 0] = X1Y0; + cm.Matrix[2, 0] = X2Y0; + cm.Matrix[0, 1] = X0Y1; + cm.Matrix[1, 1] = X1Y1; + cm.Matrix[2, 1] = X2Y1; + cm.Matrix[0, 2] = X0Y2; + cm.Matrix[1, 2] = X1Y2; + cm.Matrix[2, 2] = X2Y2; + cm.Factor = Factor; + cm.Offset = Offset; + return cm.Apply(img); + } + } + } +} \ No newline at end of file diff --git a/ImageEffectsLib/ImageEffectsForm.cs b/ImageEffectsLib/ImageEffectsForm.cs index d82a7b1c8..f494ef6a0 100644 --- a/ImageEffectsLib/ImageEffectsForm.cs +++ b/ImageEffectsLib/ImageEffectsForm.cs @@ -82,7 +82,7 @@ private void AddAllEffectsToTreeView() typeof(Grayscale), typeof(Hue), typeof(Inverse), - typeof(Matrix), + typeof(MatrixColor), typeof(Polaroid), typeof(Saturation), typeof(Sepia)); @@ -92,6 +92,7 @@ private void AddAllEffectsToTreeView() typeof(EdgeDetect), typeof(Emboss), typeof(GaussianBlur), + typeof(MatrixConvolution), typeof(MeanRemoval), typeof(Pixelate), typeof(Reflection), diff --git a/ImageEffectsLib/ImageEffectsLib.csproj b/ImageEffectsLib/ImageEffectsLib.csproj index 1725ff0ed..5451583f7 100644 --- a/ImageEffectsLib/ImageEffectsLib.csproj +++ b/ImageEffectsLib/ImageEffectsLib.csproj @@ -74,10 +74,11 @@ - + +