From a05db9b66af15d3a413b25586610e5314def5dae Mon Sep 17 00:00:00 2001 From: L1Q <0xL1Q@ex.ua> Date: Fri, 3 Jul 2020 10:31:39 +0300 Subject: [PATCH] Add RGB Split image effect --- ShareX.ImageEffectsLib/Filters/RGBSplit.cs | 70 +++++++++++++++++++ ShareX.ImageEffectsLib/ImageEffectsForm.cs | 1 + .../ShareX.ImageEffectsLib.csproj | 1 + 3 files changed, 72 insertions(+) create mode 100644 ShareX.ImageEffectsLib/Filters/RGBSplit.cs diff --git a/ShareX.ImageEffectsLib/Filters/RGBSplit.cs b/ShareX.ImageEffectsLib/Filters/RGBSplit.cs new file mode 100644 index 000000000..3feb2f39a --- /dev/null +++ b/ShareX.ImageEffectsLib/Filters/RGBSplit.cs @@ -0,0 +1,70 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (c) 2007-2020 ShareX Team + + 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 ShareX.HelpersLib; +using System.ComponentModel; +using System.Drawing; +using System.Drawing.Imaging; + +namespace ShareX.ImageEffectsLib +{ + [Description("RGB Split")] + internal class RGBSplit : ImageEffect + { + [DefaultValue(typeof(Point), "5, 0")] + public Point OffsetRed { get; set; } + [DefaultValue(typeof(Point), "0, 0")] + public Point OffsetGreen { get; set; } + [DefaultValue(typeof(Point), "-5, 0")] + public Point OffsetBlue { get; set; } + + public override Bitmap Apply(Bitmap bmp) + { + Bitmap bmpResult = bmp.CreateEmptyBitmap(); + using (UnsafeBitmap source = new UnsafeBitmap(bmp, true, ImageLockMode.ReadOnly)) + using (UnsafeBitmap dest = new UnsafeBitmap(bmpResult, true, ImageLockMode.WriteOnly)) + { + for (int y = 0; y < dest.Height; y++) + { + for (int x = 0; x < dest.Width; x++) + { + ColorBgra colorR = source.GetPixel(MathHelpers.Clamp(x + OffsetRed.X, 0, dest.Width - 1), MathHelpers.Clamp(y + OffsetRed.Y, 0, dest.Height - 1)); + ColorBgra colorG = source.GetPixel(MathHelpers.Clamp(x + OffsetGreen.X, 0, dest.Width - 1), MathHelpers.Clamp(y + OffsetGreen.Y, 0, dest.Height - 1)); + ColorBgra colorB = source.GetPixel(MathHelpers.Clamp(x + OffsetBlue.X, 0, dest.Width - 1), MathHelpers.Clamp(y + OffsetBlue.Y, 0, dest.Height - 1)); + + byte colorR_alpha = colorR.Alpha; + byte colorG_alpha = colorG.Alpha; + byte colorB_alpha = colorB.Alpha; + byte colorA = (byte)((colorR_alpha / 3 + colorG_alpha / 3 + colorB_alpha / 3)); + + ColorBgra shiftedcolor = new ColorBgra((byte)(colorB.Blue * colorB_alpha / 255), (byte)(colorG.Green * colorG_alpha / 255), (byte)(colorR.Red * colorR_alpha / 255), colorA); + dest.SetPixel(x, y, shiftedcolor); + } + } + } + return bmpResult; + } + } +} \ No newline at end of file diff --git a/ShareX.ImageEffectsLib/ImageEffectsForm.cs b/ShareX.ImageEffectsLib/ImageEffectsForm.cs index f78846e9b..9ab7e16c6 100644 --- a/ShareX.ImageEffectsLib/ImageEffectsForm.cs +++ b/ShareX.ImageEffectsLib/ImageEffectsForm.cs @@ -162,6 +162,7 @@ private void AddAllEffectsToContextMenu() typeof(MeanRemoval), typeof(Outline), typeof(Pixelate), + typeof(RGBSplit), typeof(Reflection), typeof(Shadow), typeof(Sharpen), diff --git a/ShareX.ImageEffectsLib/ShareX.ImageEffectsLib.csproj b/ShareX.ImageEffectsLib/ShareX.ImageEffectsLib.csproj index 58be5dbe3..806400e34 100644 --- a/ShareX.ImageEffectsLib/ShareX.ImageEffectsLib.csproj +++ b/ShareX.ImageEffectsLib/ShareX.ImageEffectsLib.csproj @@ -119,6 +119,7 @@ +