From 46c8c4b778e4f1cafce4735ded8725f956db0eaa Mon Sep 17 00:00:00 2001 From: Michael Ryan Date: Mon, 14 Sep 2020 12:22:56 -0700 Subject: [PATCH 1/2] Fixed the following compiler errors and warning. * QuickTaskInfoEditForm.cs(57, 124): [CS8107] Feature 'enum generic type constraints' is not available in C# 7.0. Please use language version 7.3 or greater. * VideoConverterForm.cs(177, 25): [CS0121] The call is ambiguous between the following methods or properties: 'Task.Run(Func)' and 'Task.Run(Func)' * HashCheck.cs(65, 55): [CS0168] The variable 'e' is declared but never used --- ShareX.HelpersLib/Cryptographic/HashCheck.cs | 2 +- ShareX.MediaLib/Forms/VideoConverterForm.cs | 2 +- ShareX/ShareX.csproj | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) 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.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 From 83c3dcedff27b0ec0881f3c182ccef876ecbcb95 Mon Sep 17 00:00:00 2001 From: Michael Ryan Date: Mon, 14 Sep 2020 12:45:26 -0700 Subject: [PATCH 2/2] * Added "Color depth" filter that remaps RGB pixel color to the nearest color at the specified color depth. For example, #E1CB96 will be remapped to #DDCC99 when "BitsPerChannel" is set to 4. * Fixed the menu items order of "Drawing > Particles", "Adjustments > Color matrix", and "Filters > Convolution matrix", which were not alphabetized correctly. --- ShareX.HelpersLib/Helpers/ImageHelpers.cs | 31 +++++++++++++++++++ ShareX.ImageEffectsLib/Filters/ColorDepth.cs | 30 ++++++++++++++++++ .../Forms/ImageEffectsForm.cs | 9 +++--- .../ShareX.ImageEffectsLib.csproj | 1 + 4 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 ShareX.ImageEffectsLib/Filters/ColorDepth.cs 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 @@ +