diff --git a/ShareX.HelpersLib/ConvolutionMatrixManager.cs b/ShareX.HelpersLib/ConvolutionMatrixManager.cs index 3dfa44a55..3506c3618 100644 --- a/ShareX.HelpersLib/ConvolutionMatrixManager.cs +++ b/ShareX.HelpersLib/ConvolutionMatrixManager.cs @@ -35,12 +35,12 @@ namespace ShareX.HelpersLib { public static class ConvolutionMatrixManager { - public static Image Apply(this ConvolutionMatrix kernel, Image img) + public static Bitmap Apply(this ConvolutionMatrix kernel, Bitmap bmp) { - Bitmap result = (Bitmap)img.Clone(); + Bitmap bmpResult = (Bitmap)bmp.Clone(); - using (UnsafeBitmap source = new UnsafeBitmap((Bitmap)img, true, ImageLockMode.ReadOnly)) - using (UnsafeBitmap dest = new UnsafeBitmap(result, true, ImageLockMode.WriteOnly)) + using (UnsafeBitmap source = new UnsafeBitmap(bmp, true, ImageLockMode.ReadOnly)) + using (UnsafeBitmap dest = new UnsafeBitmap(bmpResult, true, ImageLockMode.WriteOnly)) { int originX = (kernel.Width - 1) / 2; int originY = (kernel.Height - 1) / 2; @@ -96,23 +96,12 @@ public static Image Apply(this ConvolutionMatrix kernel, Image img) a = a.Clamp(0, 255); } - dest.SetPixel( - x, - y, - new ColorBgra( - (byte)b, - (byte)g, - (byte)r, - kernel.ConsiderAlpha - ? (byte)a - : source.GetPixel(x, y).Alpha - ) - ); + dest.SetPixel(x, y, new ColorBgra((byte)b, (byte)g, (byte)r, kernel.ConsiderAlpha ? (byte)a : source.GetPixel(x, y).Alpha)); }); }); } - return result; + return bmpResult; } public static ConvolutionMatrix Smooth(int weight = 1) diff --git a/ShareX.HelpersLib/Helpers/ImageHelpers.cs b/ShareX.HelpersLib/Helpers/ImageHelpers.cs index 8d4f6ed05..0be1ead41 100644 --- a/ShareX.HelpersLib/Helpers/ImageHelpers.cs +++ b/ShareX.HelpersLib/Helpers/ImageHelpers.cs @@ -469,9 +469,9 @@ public static Image RoundedCorners(Image img, int cornerRadius) return bmp; } - public static Image Outline(Image img, int borderSize, Color borderColor) + public static Bitmap Outline(Bitmap bmp, int borderSize, Color borderColor) { - Bitmap result = img.CreateEmptyBitmap(borderSize * 2, borderSize * 2); + Bitmap bmpResult = bmp.CreateEmptyBitmap(borderSize * 2, borderSize * 2); ColorMatrix maskMatrix = new ColorMatrix(); maskMatrix.Matrix00 = 0; @@ -482,9 +482,9 @@ public static Image Outline(Image img, int borderSize, Color borderColor) maskMatrix.Matrix41 = ((float)borderColor.G).Remap(0, 255, 0, 1); maskMatrix.Matrix42 = ((float)borderColor.B).Remap(0, 255, 0, 1); - using (img) - using (Image shadow = maskMatrix.Apply(img)) - using (Graphics g = Graphics.FromImage(result)) + using (bmp) + using (Image shadow = maskMatrix.Apply(bmp)) + using (Graphics g = Graphics.FromImage(bmpResult)) { for (int i = 0; i <= borderSize * 2; i++) { @@ -494,33 +494,33 @@ public static Image Outline(Image img, int borderSize, Color borderColor) g.DrawImage(shadow, new Rectangle(borderSize * 2, i, shadow.Width, shadow.Height)); } - g.DrawImage(img, new Rectangle(borderSize, borderSize, img.Width, img.Height)); + g.DrawImage(bmp, new Rectangle(borderSize, borderSize, bmp.Width, bmp.Height)); } - return result; + return bmpResult; } - public static Image DrawReflection(Image img, int percentage, int maxAlpha, int minAlpha, int offset, bool skew, int skewSize) + public static Bitmap DrawReflection(Bitmap bmp, int percentage, int maxAlpha, int minAlpha, int offset, bool skew, int skewSize) { - Bitmap reflection = AddReflection(img, percentage, maxAlpha, minAlpha); + Bitmap reflection = AddReflection(bmp, percentage, maxAlpha, minAlpha); if (skew) { reflection = AddSkew(reflection, skewSize, 0); } - Bitmap result = new Bitmap(reflection.Width, img.Height + reflection.Height + offset); + Bitmap bmpResult = new Bitmap(reflection.Width, bmp.Height + reflection.Height + offset); - using (Graphics g = Graphics.FromImage(result)) - using (img) + using (bmp) using (reflection) + using (Graphics g = Graphics.FromImage(bmpResult)) { g.SetHighQuality(); - g.DrawImage(img, 0, 0, img.Width, img.Height); - g.DrawImage(reflection, 0, img.Height + offset, reflection.Width, reflection.Height); + g.DrawImage(bmp, 0, 0, bmp.Width, bmp.Height); + g.DrawImage(reflection, 0, bmp.Height + offset, reflection.Width, reflection.Height); } - return result; + return bmpResult; } public static Bitmap AddSkew(Image img, int x, int y) @@ -910,18 +910,18 @@ public static Bitmap RotateImage(Image img, float angleDegrees, bool upsize, boo return newBitmap; } - public static Bitmap AddShadow(Image img, float opacity, int size) + public static Bitmap AddShadow(Bitmap bmp, float opacity, int size) { - return AddShadow(img, opacity, size, 1, Color.Black, new Point(0, 0)); + return AddShadow(bmp, opacity, size, 1, Color.Black, new Point(0, 0)); } - public static Bitmap AddShadow(Image img, float opacity, int size, float darkness, Color color, Point offset) + public static Bitmap AddShadow(Bitmap bmp, float opacity, int size, float darkness, Color color, Point offset) { Bitmap shadowImage = null; try { - shadowImage = img.CreateEmptyBitmap(size * 2, size * 2); + shadowImage = bmp.CreateEmptyBitmap(size * 2, size * 2); ColorMatrix maskMatrix = new ColorMatrix(); maskMatrix.Matrix00 = 0; @@ -932,8 +932,8 @@ public static Bitmap AddShadow(Image img, float opacity, int size, float darknes maskMatrix.Matrix41 = ((float)color.G).Remap(0, 255, 0, 1); maskMatrix.Matrix42 = ((float)color.B).Remap(0, 255, 0, 1); - Rectangle shadowRectangle = new Rectangle(size, size, img.Width, img.Height); - maskMatrix.Apply(img, shadowImage, shadowRectangle); + Rectangle shadowRectangle = new Rectangle(size, size, bmp.Width, bmp.Height); + maskMatrix.Apply(bmp, shadowImage, shadowRectangle); if (size > 0) { @@ -945,25 +945,25 @@ public static Bitmap AddShadow(Image img, float opacity, int size, float darknes ColorMatrix alphaMatrix = new ColorMatrix(); alphaMatrix.Matrix33 = darkness; - Bitmap shadowImage2 = (Bitmap)alphaMatrix.Apply(shadowImage); + Bitmap shadowImage2 = alphaMatrix.Apply(shadowImage); shadowImage.Dispose(); shadowImage = shadowImage2; } - Bitmap result = shadowImage.CreateEmptyBitmap(Math.Abs(offset.X), Math.Abs(offset.Y)); + Bitmap bmpResult = shadowImage.CreateEmptyBitmap(Math.Abs(offset.X), Math.Abs(offset.Y)); - using (Graphics g = Graphics.FromImage(result)) + using (Graphics g = Graphics.FromImage(bmpResult)) { g.SetHighQuality(); g.DrawImage(shadowImage, Math.Max(0, offset.X), Math.Max(0, offset.Y), shadowImage.Width, shadowImage.Height); - g.DrawImage(img, Math.Max(size, -offset.X + size), Math.Max(size, -offset.Y + size), img.Width, img.Height); + g.DrawImage(bmp, Math.Max(size, -offset.X + size), Math.Max(size, -offset.Y + size), bmp.Width, bmp.Height); } - return result; + return bmpResult; } finally { - if (img != null) img.Dispose(); + if (bmp != null) bmp.Dispose(); if (shadowImage != null) shadowImage.Dispose(); } } @@ -1416,17 +1416,17 @@ public static void FastBoxBlur(Bitmap bmp, int radius) } } - public static Image TornEdges(Image img, int tornDepth, int tornRange, AnchorStyles sides, bool curvedEdges) + public static Bitmap TornEdges(Bitmap bmp, int tornDepth, int tornRange, AnchorStyles sides, bool curvedEdges) { if (tornDepth < 1 || tornRange < 1 || sides == AnchorStyles.None) { - return img; + return bmp; } List points = new List(); - int horizontalTornCount = img.Width / tornRange; - int verticalTornCount = img.Height / tornRange; + int horizontalTornCount = bmp.Width / tornRange; + int verticalTornCount = bmp.Height / tornRange; if (sides.HasFlag(AnchorStyles.Top)) { @@ -1438,53 +1438,53 @@ public static Image TornEdges(Image img, int tornDepth, int tornRange, AnchorSty else { points.Add(new Point(0, 0)); - points.Add(new Point(img.Width - 1, 0)); + points.Add(new Point(bmp.Width - 1, 0)); } if (sides.HasFlag(AnchorStyles.Right)) { for (int y = 0; y < verticalTornCount - 1; y++) { - points.Add(new Point(img.Width - 1 - MathHelpers.Random(0, tornDepth), tornRange * y)); + points.Add(new Point(bmp.Width - 1 - MathHelpers.Random(0, tornDepth), tornRange * y)); } } else { - points.Add(new Point(img.Width - 1, 0)); - points.Add(new Point(img.Width - 1, img.Height - 1)); + points.Add(new Point(bmp.Width - 1, 0)); + points.Add(new Point(bmp.Width - 1, bmp.Height - 1)); } if (sides.HasFlag(AnchorStyles.Bottom)) { for (int x = 0; x < horizontalTornCount - 1; x++) { - points.Add(new Point(img.Width - 1 - (tornRange * x), img.Height - 1 - MathHelpers.Random(0, tornDepth))); + points.Add(new Point(bmp.Width - 1 - (tornRange * x), bmp.Height - 1 - MathHelpers.Random(0, tornDepth))); } } else { - points.Add(new Point(img.Width - 1, img.Height - 1)); - points.Add(new Point(0, img.Height - 1)); + points.Add(new Point(bmp.Width - 1, bmp.Height - 1)); + points.Add(new Point(0, bmp.Height - 1)); } if (sides.HasFlag(AnchorStyles.Left)) { for (int y = 0; y < verticalTornCount - 1; y++) { - points.Add(new Point(MathHelpers.Random(0, tornDepth), img.Height - 1 - (tornRange * y))); + points.Add(new Point(MathHelpers.Random(0, tornDepth), bmp.Height - 1 - (tornRange * y))); } } else { - points.Add(new Point(0, img.Height - 1)); + points.Add(new Point(0, bmp.Height - 1)); points.Add(new Point(0, 0)); } - Bitmap result = img.CreateEmptyBitmap(); + Bitmap bmpResult = bmp.CreateEmptyBitmap(); - using (img) - using (Graphics g = Graphics.FromImage(result)) - using (TextureBrush brush = new TextureBrush(img)) + using (bmp) + using (Graphics g = Graphics.FromImage(bmpResult)) + using (TextureBrush brush = new TextureBrush(bmp)) { g.SetHighQuality(); @@ -1498,22 +1498,22 @@ public static Image TornEdges(Image img, int tornDepth, int tornRange, AnchorSty { g.FillPolygon(brush, fillPoints); } - - return result; } + + return bmpResult; } - public static Bitmap Slice(Image img, int minSliceHeight, int maxSliceHeight, int minSliceShift, int maxSliceShift) + public static Bitmap Slice(Bitmap bmp, int minSliceHeight, int maxSliceHeight, int minSliceShift, int maxSliceShift) { - Bitmap result = img.CreateEmptyBitmap(); + Bitmap bmpResult = bmp.CreateEmptyBitmap(); - using (Graphics g = Graphics.FromImage(result)) + using (Graphics g = Graphics.FromImage(bmpResult)) { int y = 0; - while (y < img.Height) + while (y < bmp.Height) { - Rectangle sourceRect = new Rectangle(0, y, img.Width, MathHelpers.Random(minSliceHeight, maxSliceHeight)); + Rectangle sourceRect = new Rectangle(0, y, bmp.Width, MathHelpers.Random(minSliceHeight, maxSliceHeight)); Rectangle destRect = sourceRect; if (MathHelpers.Random(1) == 0) // Shift left @@ -1525,13 +1525,13 @@ public static Bitmap Slice(Image img, int minSliceHeight, int maxSliceHeight, in destRect.X = MathHelpers.Random(minSliceShift, maxSliceShift); } - g.DrawImage(img, destRect, sourceRect, GraphicsUnit.Pixel); + g.DrawImage(bmp, destRect, sourceRect, GraphicsUnit.Pixel); y += sourceRect.Height; } } - return result; + return bmpResult; } public static string OpenImageFileDialog(Form form = null) diff --git a/ShareX.ImageEffectsLib/Filters/Blur.cs b/ShareX.ImageEffectsLib/Filters/Blur.cs index fe296d01e..c08286ddf 100644 --- a/ShareX.ImageEffectsLib/Filters/Blur.cs +++ b/ShareX.ImageEffectsLib/Filters/Blur.cs @@ -56,10 +56,10 @@ public Blur() this.ApplyDefaultPropertyValues(); } - public override Image Apply(Image img) + public override Bitmap Apply(Bitmap bmp) { - ImageHelpers.BoxBlur((Bitmap)img, Radius); - return img; + ImageHelpers.BoxBlur(bmp, Radius); + return bmp; } } } \ No newline at end of file diff --git a/ShareX.ImageEffectsLib/Filters/EdgeDetect.cs b/ShareX.ImageEffectsLib/Filters/EdgeDetect.cs index af33f3de6..b9b4ee70f 100644 --- a/ShareX.ImageEffectsLib/Filters/EdgeDetect.cs +++ b/ShareX.ImageEffectsLib/Filters/EdgeDetect.cs @@ -32,11 +32,11 @@ namespace ShareX.ImageEffectsLib [Description("Edge detect")] internal class EdgeDetect : ImageEffect { - public override Image Apply(Image img) + public override Bitmap Apply(Bitmap bmp) { - using (img) + using (bmp) { - return ConvolutionMatrixManager.EdgeDetect().Apply(img); + return ConvolutionMatrixManager.EdgeDetect().Apply(bmp); } } } diff --git a/ShareX.ImageEffectsLib/Filters/Emboss.cs b/ShareX.ImageEffectsLib/Filters/Emboss.cs index 8615256c9..a7f018521 100644 --- a/ShareX.ImageEffectsLib/Filters/Emboss.cs +++ b/ShareX.ImageEffectsLib/Filters/Emboss.cs @@ -30,11 +30,11 @@ namespace ShareX.ImageEffectsLib { internal class Emboss : ImageEffect { - public override Image Apply(Image img) + public override Bitmap Apply(Bitmap bmp) { - using (img) + using (bmp) { - return ConvolutionMatrixManager.Emboss().Apply(img); + return ConvolutionMatrixManager.Emboss().Apply(bmp); } } } diff --git a/ShareX.ImageEffectsLib/Filters/GaussianBlur.cs b/ShareX.ImageEffectsLib/Filters/GaussianBlur.cs index fe4d2c562..54d9c00ac 100644 --- a/ShareX.ImageEffectsLib/Filters/GaussianBlur.cs +++ b/ShareX.ImageEffectsLib/Filters/GaussianBlur.cs @@ -63,7 +63,7 @@ public GaussianBlur() this.ApplyDefaultPropertyValues(); } - public override Image Apply(Image img) + public override Bitmap Apply(Bitmap bmp) { ConvolutionMatrix kernelHoriz = ConvolutionMatrixManager.GaussianBlur(1, size, sigma); @@ -77,8 +77,8 @@ public override Image Apply(Image img) kernelVert[i, 0] = kernelHoriz[0, i]; } - using (img) - using (Image horizPass = kernelHoriz.Apply(img)) + using (bmp) + using (Bitmap horizPass = kernelHoriz.Apply(bmp)) { return kernelVert.Apply(horizPass); } diff --git a/ShareX.ImageEffectsLib/Filters/MatrixConvolution.cs b/ShareX.ImageEffectsLib/Filters/MatrixConvolution.cs index d519ac1af..4887e97e6 100644 --- a/ShareX.ImageEffectsLib/Filters/MatrixConvolution.cs +++ b/ShareX.ImageEffectsLib/Filters/MatrixConvolution.cs @@ -64,9 +64,9 @@ public MatrixConvolution() this.ApplyDefaultPropertyValues(); } - public override Image Apply(Image img) + public override Bitmap Apply(Bitmap bmp) { - using (img) + using (bmp) { ConvolutionMatrix cm = new ConvolutionMatrix(); cm[0, 0] = X0Y0 / Factor; @@ -79,7 +79,7 @@ public override Image Apply(Image img) cm[2, 1] = X1Y2 / Factor; cm[2, 2] = X2Y2 / Factor; cm.Offset = Offset; - return cm.Apply(img); + return cm.Apply(bmp); } } } diff --git a/ShareX.ImageEffectsLib/Filters/MeanRemoval.cs b/ShareX.ImageEffectsLib/Filters/MeanRemoval.cs index 1a7e4c17c..67e5ef5a9 100644 --- a/ShareX.ImageEffectsLib/Filters/MeanRemoval.cs +++ b/ShareX.ImageEffectsLib/Filters/MeanRemoval.cs @@ -32,11 +32,11 @@ namespace ShareX.ImageEffectsLib [Description("Mean removal")] internal class MeanRemoval : ImageEffect { - public override Image Apply(Image img) + public override Bitmap Apply(Bitmap bmp) { - using (img) + using (bmp) { - return ConvolutionMatrixManager.MeanRemoval().Apply(img); + return ConvolutionMatrixManager.MeanRemoval().Apply(bmp); } } } diff --git a/ShareX.ImageEffectsLib/Filters/Outline.cs b/ShareX.ImageEffectsLib/Filters/Outline.cs index 2e4a14e82..49b09fbaf 100644 --- a/ShareX.ImageEffectsLib/Filters/Outline.cs +++ b/ShareX.ImageEffectsLib/Filters/Outline.cs @@ -55,9 +55,9 @@ public Outline() this.ApplyDefaultPropertyValues(); } - public override Image Apply(Image img) + public override Bitmap Apply(Bitmap bmp) { - return ImageHelpers.Outline(img, Size, Color); + return ImageHelpers.Outline(bmp, Size, Color); } } } \ No newline at end of file diff --git a/ShareX.ImageEffectsLib/Filters/Pixelate.cs b/ShareX.ImageEffectsLib/Filters/Pixelate.cs index 94ecb0818..564450070 100644 --- a/ShareX.ImageEffectsLib/Filters/Pixelate.cs +++ b/ShareX.ImageEffectsLib/Filters/Pixelate.cs @@ -51,10 +51,10 @@ public Pixelate() this.ApplyDefaultPropertyValues(); } - public override Image Apply(Image img) + public override Bitmap Apply(Bitmap bmp) { - ImageHelpers.Pixelate((Bitmap)img, Size); - return img; + ImageHelpers.Pixelate(bmp, Size); + return bmp; } } } \ No newline at end of file diff --git a/ShareX.ImageEffectsLib/Filters/Reflection.cs b/ShareX.ImageEffectsLib/Filters/Reflection.cs index 89bee2eb0..966a49af5 100644 --- a/ShareX.ImageEffectsLib/Filters/Reflection.cs +++ b/ShareX.ImageEffectsLib/Filters/Reflection.cs @@ -90,9 +90,9 @@ public Reflection() this.ApplyDefaultPropertyValues(); } - public override Image Apply(Image img) + public override Bitmap Apply(Bitmap bmp) { - return ImageHelpers.DrawReflection(img, Percentage, MaxAlpha, MinAlpha, Offset, Skew, SkewSize); + return ImageHelpers.DrawReflection(bmp, Percentage, MaxAlpha, MinAlpha, Offset, Skew, SkewSize); } } } \ No newline at end of file diff --git a/ShareX.ImageEffectsLib/Filters/Shadow.cs b/ShareX.ImageEffectsLib/Filters/Shadow.cs index b620ce1e9..a5782a909 100644 --- a/ShareX.ImageEffectsLib/Filters/Shadow.cs +++ b/ShareX.ImageEffectsLib/Filters/Shadow.cs @@ -76,9 +76,9 @@ public Shadow() this.ApplyDefaultPropertyValues(); } - public override Image Apply(Image img) + public override Bitmap Apply(Bitmap bmp) { - return ImageHelpers.AddShadow(img, Opacity, Size, Darkness + 1, Color, Offset); + return ImageHelpers.AddShadow(bmp, Opacity, Size, Darkness + 1, Color, Offset); } } } \ No newline at end of file diff --git a/ShareX.ImageEffectsLib/Filters/Sharpen.cs b/ShareX.ImageEffectsLib/Filters/Sharpen.cs index 7c24a7051..f392ba7c7 100644 --- a/ShareX.ImageEffectsLib/Filters/Sharpen.cs +++ b/ShareX.ImageEffectsLib/Filters/Sharpen.cs @@ -30,13 +30,13 @@ namespace ShareX.ImageEffectsLib { internal class Sharpen : ImageEffect { - public override Image Apply(Image img) + public override Bitmap Apply(Bitmap bmp) { - //return ImageHelpers.Sharpen(img, Strength); + //return ImageHelpers.Sharpen(bmp, Strength); - using (img) + using (bmp) { - return ConvolutionMatrixManager.Sharpen().Apply(img); + return ConvolutionMatrixManager.Sharpen().Apply(bmp); } } } diff --git a/ShareX.ImageEffectsLib/Filters/Slice.cs b/ShareX.ImageEffectsLib/Filters/Slice.cs index 51bbb039a..2e21ab8fd 100644 --- a/ShareX.ImageEffectsLib/Filters/Slice.cs +++ b/ShareX.ImageEffectsLib/Filters/Slice.cs @@ -50,16 +50,16 @@ public Slice() this.ApplyDefaultPropertyValues(); } - public override Image Apply(Image img) + public override Bitmap Apply(Bitmap bmp) { int minSliceHeight = Math.Min(MinSliceHeight, MaxSliceHeight); int maxSliceHeight = Math.Max(MinSliceHeight, MaxSliceHeight); int minSliceShift = Math.Min(MinSliceShift, MaxSliceShift); int maxSliceShift = Math.Max(MinSliceShift, MaxSliceShift); - using (img) + using (bmp) { - return ImageHelpers.Slice(img, minSliceHeight, maxSliceHeight, minSliceShift, maxSliceShift); + return ImageHelpers.Slice(bmp, minSliceHeight, maxSliceHeight, minSliceShift, maxSliceShift); } } } diff --git a/ShareX.ImageEffectsLib/Filters/Smooth.cs b/ShareX.ImageEffectsLib/Filters/Smooth.cs index 903542925..5795bb4a5 100644 --- a/ShareX.ImageEffectsLib/Filters/Smooth.cs +++ b/ShareX.ImageEffectsLib/Filters/Smooth.cs @@ -30,11 +30,11 @@ namespace ShareX.ImageEffectsLib { internal class Smooth : ImageEffect { - public override Image Apply(Image img) + public override Bitmap Apply(Bitmap bmp) { - using (img) + using (bmp) { - return ConvolutionMatrixManager.Smooth().Apply(img); + return ConvolutionMatrixManager.Smooth().Apply(bmp); } } } diff --git a/ShareX.ImageEffectsLib/Filters/TornEdge.cs b/ShareX.ImageEffectsLib/Filters/TornEdge.cs index c5f61a3eb..b720d773c 100644 --- a/ShareX.ImageEffectsLib/Filters/TornEdge.cs +++ b/ShareX.ImageEffectsLib/Filters/TornEdge.cs @@ -50,9 +50,9 @@ public TornEdge() this.ApplyDefaultPropertyValues(); } - public override Image Apply(Image img) + public override Bitmap Apply(Bitmap bmp) { - return ImageHelpers.TornEdges(img, Depth, Range, Sides, CurvedEdges); + return ImageHelpers.TornEdges(bmp, Depth, Range, Sides, CurvedEdges); } } } \ No newline at end of file