Code refactor

This commit is contained in:
Jaex 2020-07-03 14:18:47 +03:00
parent c6e99f495a
commit 423b4d6860
2 changed files with 12 additions and 9 deletions

View file

@ -30,19 +30,20 @@ You should have received a copy of the GNU General Public License
namespace ShareX.ImageEffectsLib namespace ShareX.ImageEffectsLib
{ {
[Description("RGB Split")] [Description("RGB split")]
internal class RGBSplit : ImageEffect internal class RGBSplit : ImageEffect
{ {
[DefaultValue(typeof(Point), "5, 0")] [DefaultValue(typeof(Point), "-5, 0")]
public Point OffsetRed { get; set; } public Point OffsetRed { get; set; } = new Point(-5, 0);
[DefaultValue(typeof(Point), "0, 0")] [DefaultValue(typeof(Point), "0, 0")]
public Point OffsetGreen { get; set; } public Point OffsetGreen { get; set; }
[DefaultValue(typeof(Point), "-5, 0")] [DefaultValue(typeof(Point), "5, 0")]
public Point OffsetBlue { get; set; } public Point OffsetBlue { get; set; } = new Point(5, 0);
public override Bitmap Apply(Bitmap bmp) public override Bitmap Apply(Bitmap bmp)
{ {
Bitmap bmpResult = bmp.CreateEmptyBitmap(); Bitmap bmpResult = bmp.CreateEmptyBitmap();
using (UnsafeBitmap source = new UnsafeBitmap(bmp, true, ImageLockMode.ReadOnly)) using (UnsafeBitmap source = new UnsafeBitmap(bmp, true, ImageLockMode.ReadOnly))
using (UnsafeBitmap dest = new UnsafeBitmap(bmpResult, true, ImageLockMode.WriteOnly)) using (UnsafeBitmap dest = new UnsafeBitmap(bmpResult, true, ImageLockMode.WriteOnly))
{ {
@ -57,13 +58,15 @@ public override Bitmap Apply(Bitmap bmp)
byte colorR_alpha = colorR.Alpha; byte colorR_alpha = colorR.Alpha;
byte colorG_alpha = colorG.Alpha; byte colorG_alpha = colorG.Alpha;
byte colorB_alpha = colorB.Alpha; byte colorB_alpha = colorB.Alpha;
byte colorA = (byte)((colorR_alpha / 3 + colorG_alpha / 3 + colorB_alpha / 3)); 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); ColorBgra shiftedColor = new ColorBgra((byte)(colorB.Blue * colorB_alpha / 255), (byte)(colorG.Green * colorG_alpha / 255),
dest.SetPixel(x, y, shiftedcolor); (byte)(colorR.Red * colorR_alpha / 255), colorA);
dest.SetPixel(x, y, shiftedColor);
} }
} }
} }
return bmpResult; return bmpResult;
} }
} }

View file

@ -162,8 +162,8 @@ private void AddAllEffectsToContextMenu()
typeof(MeanRemoval), typeof(MeanRemoval),
typeof(Outline), typeof(Outline),
typeof(Pixelate), typeof(Pixelate),
typeof(RGBSplit),
typeof(Reflection), typeof(Reflection),
typeof(RGBSplit),
typeof(Shadow), typeof(Shadow),
typeof(Sharpen), typeof(Sharpen),
typeof(Slice), typeof(Slice),