diff --git a/ShareX.HelpersLib/Cryptographic/HashCheck.cs b/ShareX.HelpersLib/Cryptographic/HashCheck.cs index fb9c8e843..04d953d29 100644 --- a/ShareX.HelpersLib/Cryptographic/HashCheck.cs +++ b/ShareX.HelpersLib/Cryptographic/HashCheck.cs @@ -62,7 +62,7 @@ public async Task Start(string filePath, HashType hashType) { return HashCheckThread(filePath, hashType, progress, cts.Token); } - catch (OperationCanceledException e) + catch (OperationCanceledException) { } diff --git a/ShareX.HelpersLib/Helpers/ImageHelpers.cs b/ShareX.HelpersLib/Helpers/ImageHelpers.cs index bc35a30c8..3cc5af65d 100644 --- a/ShareX.HelpersLib/Helpers/ImageHelpers.cs +++ b/ShareX.HelpersLib/Helpers/ImageHelpers.cs @@ -1378,6 +1378,37 @@ private static void BoxBlurVertical(UnsafeBitmap unsafeBitmap, int range, Rectan } } + public static void ColorDepth(Bitmap bmp, int bitsPerChannel = 4) + { + if (bitsPerChannel < 1 || bitsPerChannel > 8) + { + return; + } + + double colorsPerChannel = Math.Pow(2, bitsPerChannel); + double colorInterval = 255 / (colorsPerChannel - 1); + + byte Remap(byte color, double interval) + { + return (byte) Math.Round((Math.Round(color / interval) * interval)); + } + + using (UnsafeBitmap unsafeBitmap = new UnsafeBitmap(bmp, true)) + { + for (int y = 0; y < unsafeBitmap.Height; y++) + { + for (int x = 0; x < unsafeBitmap.Width; x++) + { + ColorBgra color = unsafeBitmap.GetPixel(x, y); + color.Red = Remap(color.Red, colorInterval); + color.Green = Remap(color.Green, colorInterval); + color.Blue = Remap(color.Blue, colorInterval); + unsafeBitmap.SetPixel(x, y, color); + } + } + } + } + // http://incubator.quasimondo.com/processing/superfast_blur.php public static void FastBoxBlur(Bitmap bmp, int radius) { diff --git a/ShareX.ImageEffectsLib/Filters/ColorDepth.cs b/ShareX.ImageEffectsLib/Filters/ColorDepth.cs new file mode 100644 index 000000000..6d714fcd2 --- /dev/null +++ b/ShareX.ImageEffectsLib/Filters/ColorDepth.cs @@ -0,0 +1,30 @@ +using System.ComponentModel; +using System.Drawing; +using ShareX.HelpersLib; + +namespace ShareX.ImageEffectsLib +{ + [Description("Color depth")] + internal class ColorDepth : ImageEffect + { + private int _bitsPerChannel; + + [DefaultValue(4)] + public int BitsPerChannel + { + get => this._bitsPerChannel; + set => this._bitsPerChannel = value.Max(1).Min(8); + } + + public ColorDepth() + { + this.ApplyDefaultPropertyValues(); + } + + public override Bitmap Apply(Bitmap bmp) + { + ImageHelpers.ColorDepth(bmp, this.BitsPerChannel); + return bmp; + } + } +} \ No newline at end of file diff --git a/ShareX.ImageEffectsLib/Forms/ImageEffectsForm.cs b/ShareX.ImageEffectsLib/Forms/ImageEffectsForm.cs index 537d01070..57f3fffa0 100644 --- a/ShareX.ImageEffectsLib/Forms/ImageEffectsForm.cs +++ b/ShareX.ImageEffectsLib/Forms/ImageEffectsForm.cs @@ -120,9 +120,9 @@ private void AddAllEffectsToContextMenu() typeof(DrawBorder), typeof(DrawCheckerboard), typeof(DrawImage), + typeof(DrawParticles), typeof(DrawTextEx), - typeof(DrawText), - typeof(DrawParticles)); + typeof(DrawText)); AddEffectToContextMenu(Resources.ImageEffectsForm_AddAllEffectsToTreeView_Manipulations, typeof(AutoCrop), @@ -140,13 +140,13 @@ private void AddAllEffectsToContextMenu() typeof(Alpha), typeof(BlackWhite), typeof(Brightness), + typeof(MatrixColor), // "Color matrix" typeof(Colorize), typeof(Contrast), typeof(Gamma), typeof(Grayscale), typeof(Hue), typeof(Inverse), - typeof(MatrixColor), typeof(Polaroid), typeof(Saturation), typeof(SelectiveColor), @@ -154,10 +154,11 @@ private void AddAllEffectsToContextMenu() AddEffectToContextMenu(Resources.ImageEffectsForm_AddAllEffectsToTreeView_Filters, typeof(Blur), + typeof(ColorDepth), + typeof(MatrixConvolution), // "Convolution matrix" typeof(EdgeDetect), typeof(Emboss), typeof(GaussianBlur), - typeof(MatrixConvolution), typeof(MeanRemoval), typeof(Outline), typeof(Pixelate), diff --git a/ShareX.ImageEffectsLib/ShareX.ImageEffectsLib.csproj b/ShareX.ImageEffectsLib/ShareX.ImageEffectsLib.csproj index df0a78aa6..cac917c2d 100644 --- a/ShareX.ImageEffectsLib/ShareX.ImageEffectsLib.csproj +++ b/ShareX.ImageEffectsLib/ShareX.ImageEffectsLib.csproj @@ -114,6 +114,7 @@ + diff --git a/ShareX.MediaLib/Forms/VideoConverterForm.cs b/ShareX.MediaLib/Forms/VideoConverterForm.cs index 091e0f57e..ad90446b0 100644 --- a/ShareX.MediaLib/Forms/VideoConverterForm.cs +++ b/ShareX.MediaLib/Forms/VideoConverterForm.cs @@ -174,7 +174,7 @@ private bool StartEncoding() private Task StartEncodingAsync() { - return Task.Run(StartEncoding); + return Task.Run(() => StartEncoding()); } private void Manager_EncodeProgressChanged(float percentage) diff --git a/ShareX/ShareX.csproj b/ShareX/ShareX.csproj index a7e990637..be109868e 100644 --- a/ShareX/ShareX.csproj +++ b/ShareX/ShareX.csproj @@ -34,6 +34,7 @@ false true true + 7.3 true