mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 17:56:51 +13:00
Merge pull request #5042 from somethingSTRANGE/master
Added "Color depth" filter
This commit is contained in:
commit
18ed2567b4
7 changed files with 70 additions and 6 deletions
|
@ -62,7 +62,7 @@ public async Task<string> Start(string filePath, HashType hashType)
|
|||
{
|
||||
return HashCheckThread(filePath, hashType, progress, cts.Token);
|
||||
}
|
||||
catch (OperationCanceledException e)
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
30
ShareX.ImageEffectsLib/Filters/ColorDepth.cs
Normal file
30
ShareX.ImageEffectsLib/Filters/ColorDepth.cs
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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),
|
||||
|
|
|
@ -114,6 +114,7 @@
|
|||
<Compile Include="Drawings\DrawText.cs" />
|
||||
<Compile Include="Drawings\DrawTextEx.cs" />
|
||||
<Compile Include="Enums.cs" />
|
||||
<Compile Include="Filters\ColorDepth.cs" />
|
||||
<Compile Include="Filters\EdgeDetect.cs" />
|
||||
<Compile Include="Filters\Emboss.cs" />
|
||||
<Compile Include="Filters\GaussianBlur.cs" />
|
||||
|
|
|
@ -174,7 +174,7 @@ private bool StartEncoding()
|
|||
|
||||
private Task<bool> StartEncodingAsync()
|
||||
{
|
||||
return Task.Run(StartEncoding);
|
||||
return Task.Run(() => StartEncoding());
|
||||
}
|
||||
|
||||
private void Manager_EncodeProgressChanged(float percentage)
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<LangVersion>7.3</LangVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
|
|
Loading…
Reference in a new issue